﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using web.core.ViewModels;
using web.core.Models;
using web.component;
using System.Configuration;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using iTextSharp.text.html.simpleparser;
using System.Web.UI;

namespace web.core.Controllers
{
    public class h_contentController : baseController
    {
        public ActionResult list_employee_family()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_employee_family(int? id, string text_search, string hometown, string current_address, string job, string birth_day)
        {
            return control_list_employee_family(id ?? 1, 10, text_search,hometown, current_address, job, birth_day);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_employee_family(int? id, int? pagesize, string text_search, string hometown, string current_address, string job, string birth_day)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var family_view = new ViewModels.PageListEmployeeFamilyViewModels();
            id = id ?? 1;
            int total_record = 0;
            family_view.list_pagesize = sizeDrop;
            family_view.pagesize = pagesize ?? 10;
            family_view.page_list_employee_family = h_contentModels.getEmployeeFamilyBuilder(id ?? 1, pagesize ?? 10, text_search ?? null, hometown, current_address, job, birth_day, ref total_record);
            family_view.job = job;
            family_view.current_address = current_address;
            family_view.birth_day = birth_day;
            family_view.hometown = hometown;
            family_view.text_search = text_search;
            family_view.total_record = total_record;
            return PartialView("../Shared/control_list_employee_family", family_view);
        }

        //Bắt đầu contronl thủy làm 
        /// <summary>
        /// danh sách trường đào tạo
        /// </summary>
        /// <returns></returns>
        public ActionResult list_school()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_school(int? id, string text_search)
        {
            return control_list_school(id ?? 1, 10, text_search);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_school(int? id, int? pagesize, string text_search)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var school_view = new ViewModels.PageListSchoolViewModels();
            id = id ?? 1;
            school_view.list_pagesize = sizeDrop;
            school_view.pagesize = pagesize ?? 10;
            school_view.page_list_school = h_contentModels.getSchoolBuilder(id ?? 1, pagesize ?? 10, text_search ?? null);
            //school_view.list_type_School = h_contentModels.listTypeSchool();
            return PartialView("../Shared/control_list_school", school_view);
        }
        /// <summary>
        /// edit school
        /// </summary>
        /// <returns></returns>
        public ActionResult edit_school()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_school(int? id)
        {
            ViewBag.isAdd = false;
            var school_view = new ViewModels.SchoolViewModels();
            var school = h_contentModels.getSchoolByID(id ?? 0);
            school_view.school_id = school.school_id;
            school_view.school_name = school.school_name;
            school_view.school_address = school.school_address;
            school_view.descriptions = school.descriptions;
            //school_view.listtype_school = h_contentModels.getListtype_school();
            school_view.school_id = id;
            return PartialView("../Shared/control_detail_school", school_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_school(FormCollection collection)
        {
            var school_view = new ViewModels.SchoolViewModels();
            TryUpdateModel(school_view);

            if (string.IsNullOrEmpty(school_view.school_name))
            {
                ViewBag.result_message = "Hãy nhập tên trường đào tạo";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_school", school_view);
            }


            var school = h_contentModels.getSchoolByID(school_view.school_id ?? 0);
            school.school_name = school_view.school_name;
            school.school_address = school_view.school_address;
            school.descriptions = school_view.descriptions;
            //school.type_school_id = school_view.type_school_id;
            h_contentModels.editSchool(school);

            ViewBag.result_message = "Sửa thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_school";
            return PartialView("../Shared/control_redirect");
        }
        /// <summary>
        /// add new school
        /// </summary>
        /// <returns></returns>
        public ActionResult add_school()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_school()
        {
            ViewBag.isAdd = true;
            var school_view = new ViewModels.SchoolViewModels();
            //school_view.listtype_school = h_contentModels.getListtype_school();
            return PartialView("../Shared/control_detail_school", school_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_school(FormCollection collection)
        {
            var school_view = new ViewModels.SchoolViewModels();
            TryUpdateModel(school_view);

            web.data.entities.school school = new data.entities.school();
            //school.type_school_id = school_view.type_school_id;
            school.school_name = school_view.school_name;
            school.school_address = school_view.school_address;
            school.descriptions = school_view.descriptions;
            int new_id = h_contentModels.createSchool(school);

            if (new_id > 0)
            {
                ViewBag.result_message = "Khởi tạo trường đào tạo thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_school";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Khởi tạo lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_school", school_view);
            }


        }





        /// <summary>
        /// object_employee
        /// </summary>
        /// <returns></returns>
        public ActionResult list_object_employee()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_object_employee(int? id, string text_search, int? parent)
        {
            return control_list_object_employee(id ?? 1, 10, text_search, parent);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_object_employee(int? id, int? pagesize, string text_search, int? parent)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var object_employee_view = new ViewModels.PageListObjectEmployeeViewModels();
            id = id ?? 1;
            object_employee_view.list_pagesize = sizeDrop;
            object_employee_view.pagesize = pagesize ?? 10;
            object_employee_view.page_list_object_employee = h_contentModels.getobject_employeeBuilder(id ?? 1, pagesize ?? 10, text_search ?? null, parent);
            object_employee_view.list_object_employee_parent = h_contentModels.getListobject_employeeByParent(null);
            return PartialView("../Shared/control_list_object_employee", object_employee_view);
        }

        public ActionResult edit_object_employee()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_object_employee(int? id)
        {
            ViewBag.isAdd = false;
            var object_employee_view = new ViewModels.ObjectEmployeeViewModels();
            var object_employee = h_contentModels.getObjectEmployeeByID(id ?? 0);
            object_employee_view.object_employee_id = object_employee.object_employee_id;
            object_employee_view.object_employee_name = object_employee.object_employee_name;
            object_employee_view.object_desc = object_employee.object_desc;
            object_employee_view.listObjectEmployeeParent = h_contentModels.getListobject_employeeBuilder(null);
            object_employee_view.parent_object = object_employee.parent_object;

            return PartialView("../Shared/control_detail_object_employee", object_employee_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_object_employee(FormCollection collection)
        {
            var object_employee_view = new ViewModels.ObjectEmployeeViewModels();
            TryUpdateModel(object_employee_view);

            if (string.IsNullOrEmpty(object_employee_view.object_employee_name))
            {
                ViewBag.result_message = "Hãy nhập tên đối tượng nhân viên.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_object_employee", object_employee_view);
            }

            var object_employee = h_contentModels.getObjectEmployeeByID(object_employee_view.object_employee_id ?? 0);
            object_employee.object_employee_name = object_employee_view.object_employee_name;
            object_employee.object_desc = object_employee_view.object_desc;
            object_employee.parent_object = object_employee_view.parent_object;

            h_contentModels.editObjectEmployee(object_employee);


            ViewBag.result_message = "cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_object_employee";
            return PartialView("../Shared/control_redirect");
        }

        public ActionResult add_object_employee()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_object_employee(int? id)
        {
            ViewBag.isAdd = true;
            var object_employee_view = new ViewModels.ObjectEmployeeViewModels();
            object_employee_view.listObjectEmployeeParent = h_contentModels.getListobject_employeeBuilder(null);
            if (id != null)
            {
                object_employee_view.parent_object = id;
            }
            return PartialView("../Shared/control_detail_object_employee", object_employee_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_object_employee(FormCollection collection)
        {
            var object_employee_view = new ViewModels.ObjectEmployeeViewModels();
            TryUpdateModel(object_employee_view);

            web.data.entities.object_employee object_employee = new data.entities.object_employee();
            object_employee.object_employee_name = object_employee_view.object_employee_name;
            object_employee.object_desc = object_employee_view.object_desc;
            object_employee.parent_object = object_employee_view.parent_object;

            int new_id = h_contentModels.createObjectEmployee(object_employee);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo đối tượng nhân viên thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_object_employee";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo không thành công.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_object_employee", object_employee_view);
            }
        }

        /// <summary>
        /// employee_foreign_countries
        /// </summary>
        /// <returns></returns>
        public ActionResult list_employee_foreign_countries()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_employee_foreign_countries(int? id, int? employee_id, string text_search)
        {
            return control_list_employee_foreign_countries(id ?? 1, 10, employee_id, text_search);
        }
        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_employee_foreign_countries(int? id, int? pagesize, int? employee_id, string text_search)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var employee_foreign_countries_view = new ViewModels.PageListEmployeeForeignCountriesViewModels();
            id = id ?? 1;
            employee_foreign_countries_view.list_pagesize = sizeDrop;
            employee_foreign_countries_view.pagesize = pagesize ?? 10;
            employee_foreign_countries_view.page_list_employee_foreign_countries = h_contentModels.getemployee_foreign_countriesBuilder(id ?? 1, pagesize ?? 10, employee_id, text_search ?? null);
            employee_foreign_countries_view.list_employee = h_contentModels.listemployee();
            return PartialView("../Shared/control_list_employee_foreign_countries", employee_foreign_countries_view);
        }

        public ActionResult edit_employee_foreign_countries()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_foreign_countries(int? employee_id, int? id)
        {
            ViewBag.isAdd = false;
            var employee_foreign_countries_view = new ViewModels.EmployeeForeignCountriesViewModels();
            var employee_foreign_countries = h_contentModels.getEmployeeForeignCountriesByID(id ?? 0);
            employee_foreign_countries_view.foreign_countries = employee_foreign_countries.foreign_countries;
            employee_foreign_countries_view.out_date = employee_foreign_countries.out_date;
            employee_foreign_countries_view.in_date = employee_foreign_countries.in_date;
            employee_foreign_countries_view.country = employee_foreign_countries.country;
            employee_foreign_countries_view.reason = employee_foreign_countries.reason;
            employee_foreign_countries_view.number_decision = employee_foreign_countries.number_decision;
            employee_foreign_countries_view.descriptions = employee_foreign_countries.descriptions;
            employee_foreign_countries_view.employee_id = employee_id;
            employee_foreign_countries_view.foreign_countries = id;
            return PartialView("../Shared/control_detail_employee_foreign_countries", employee_foreign_countries_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_foreign_countries(FormCollection collection)
        {
            var employee_foreign_countries_view = new ViewModels.EmployeeForeignCountriesViewModels();
            TryUpdateModel(employee_foreign_countries_view);

            if (string.IsNullOrEmpty(employee_foreign_countries_view.country))
            {
                ViewBag.result_message = "Hãy nhập tên.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_foreign_countries", employee_foreign_countries_view);
            }

            var employee_foreign_countries = h_contentModels.getEmployeeForeignCountriesByID(employee_foreign_countries_view.foreign_countries ?? 0);
            employee_foreign_countries.in_date = employee_foreign_countries_view.in_date;
            employee_foreign_countries.out_date = employee_foreign_countries_view.out_date;
            employee_foreign_countries.country = employee_foreign_countries_view.country;

            employee_foreign_countries.reason = employee_foreign_countries_view.reason;
            employee_foreign_countries.number_decision = employee_foreign_countries_view.number_decision;
            employee_foreign_countries.descriptions = employee_foreign_countries_view.descriptions;


            h_contentModels.editEmployeeForeignCountries(employee_foreign_countries);


            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_employee_foreign_countries";
            return PartialView("../Shared/control_redirect");
        }

        public ActionResult add_employee_foreign_countries()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_foreign_countries(int? id)
        {
            ViewBag.isAdd = true;
            var employee_foreign_countries_view = new ViewModels.EmployeeForeignCountriesViewModels();
            employee_foreign_countries_view.employee_id = id;

            return PartialView("../Shared/control_detail_employee_foreign_countries", employee_foreign_countries_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_foreign_countries(FormCollection collection)
        {
            var employee_foreign_countries_view = new ViewModels.EmployeeForeignCountriesViewModels();
            TryUpdateModel(employee_foreign_countries_view);


            web.data.entities.employee_foreign_countries employee_foreign_country = new data.entities.employee_foreign_countries();
            employee_foreign_country.in_date = employee_foreign_countries_view.in_date;
            employee_foreign_country.out_date = employee_foreign_countries_view.out_date;
            employee_foreign_country.country = employee_foreign_countries_view.country;

            employee_foreign_country.reason = employee_foreign_countries_view.reason;
            employee_foreign_country.number_decision = employee_foreign_countries_view.number_decision;
            employee_foreign_country.descriptions = employee_foreign_countries_view.descriptions;
            employee_foreign_country.employee_id = employee_foreign_countries_view.employee_id;

            int new_id = h_contentModels.createEmployeeForeignCountries(employee_foreign_country);

            if (new_id > 0)
            {

                ViewBag.result_message = "Tạo thành công";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_employee_foreign_countries";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo không thành công.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_foreign_countries", employee_foreign_countries_view);
            }
        }

        /// <summary>
        /// Employee School
        /// </summary>
        /// <returns></returns>

        public ActionResult edit_employee_school()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_school(int? employee_id, int? id)
        {
            ViewBag.isAdd = false;
            var edit_employee_school_view = new ViewModels.EmployeeSchoolViewModels();
            var edit_employee_school = h_contentModels.getEmployeeSchoolByID(id ?? 1);
            edit_employee_school_view.listschool = h_contentModels.getListSchool();
            edit_employee_school_view.school_id = edit_employee_school.school_id;
            edit_employee_school_view.courses = edit_employee_school.courses;
            edit_employee_school_view.majors = edit_employee_school.majors;
            edit_employee_school_view.study_level = edit_employee_school.study_level;
            //edit_employee_school_view.start_date = edit_employee_school.start_date;
            edit_employee_school_view.start_date_d = edit_employee_school.start_date_d;
            edit_employee_school_view.start_date_m = edit_employee_school.start_date_m;
            edit_employee_school_view.start_date_y = edit_employee_school.start_date_y;
            //edit_employee_school_view.end_date = edit_employee_school.end_date;
            edit_employee_school_view.end_date_d = edit_employee_school.end_date_d;
            edit_employee_school_view.end_date_m = edit_employee_school.end_date_m;
            edit_employee_school_view.end_date_y = edit_employee_school.end_date_y;

            edit_employee_school_view.diplomas = edit_employee_school.diplomas;
            edit_employee_school_view.created_date = edit_employee_school.created_date;
            edit_employee_school_view.modified_date = edit_employee_school.modified_date;
            edit_employee_school_view.modified_by = edit_employee_school.modified_by;
            edit_employee_school_view.created_by = edit_employee_school.created_by;

            edit_employee_school_view.descriptions = edit_employee_school.descriptions;
            edit_employee_school_view.employee_id = employee_id;
            edit_employee_school_view.employee_school_id = id;
            return PartialView("../Shared/control_detail_employee_school", edit_employee_school_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_school(FormCollection collection)
        {
            var employee_school_view = new ViewModels.EmployeeSchoolViewModels();
            TryUpdateModel(employee_school_view);
            employee_school_view.listschool = h_contentModels.getListSchool();
            var employee_school = h_contentModels.getEmployeeSchoolByID(employee_school_view.employee_school_id ?? 0);
            if (string.IsNullOrEmpty(employee_school_view.courses))
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Hãy nhập tên khóa học.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.courses = employee_school_view.courses;
            }
            if (employee_school_view.school_id != null )
            {
                employee_school.school_id = employee_school_view.school_id;
            }
            else {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Vui lòng chọn nhóm trường đào tạo";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            
            employee_school.employee_school_id = employee_school_view.employee_school_id ??0;
            employee_school.majors = employee_school_view.majors;
            employee_school.study_level = employee_school_view.study_level;
            //employee_school.start_date = employee_school_view.start_date;
            if (string.IsNullOrEmpty(employee_school_view.start_date_d) || employee_school_view.start_date_d == "0")
            {
                employee_school.start_date_d = "01";
            }
            else if (employee_school_view.start_date_d.Length == 1)
            {
                employee_school.start_date_d = "0" + employee_school_view.start_date_d;
            }
            else if (Int32.Parse(employee_school_view.start_date_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.start_date_d = employee_school_view.start_date_d;
            }
            if (string.IsNullOrEmpty(employee_school_view.start_date_m) || employee_school_view.start_date_m == "0")
            {
                employee_school.start_date_m = "01";
            }
            else if (employee_school_view.start_date_m.Length == 1)
            {
                employee_school.start_date_m = "0" + employee_school_view.start_date_m;
            }
            else if (Int32.Parse(employee_school_view.start_date_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.start_date_m = employee_school_view.start_date_m;
            }

            if (string.IsNullOrEmpty(employee_school_view.start_date_y) || Int32.Parse(employee_school_view.start_date_y) < 1900)
            {
                employee_school.start_date_y = "1900";
            }
            else if (employee_school_view.start_date_y.Length > 4 || employee_school_view.start_date_y.Length < 4 || employee_school_view.start_date_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.start_date_y = employee_school_view.start_date_y;
            }
            employee_school.start_date = DateTime.ParseExact((employee_school.start_date_d + "/" + employee_school.start_date_m + "/" + employee_school.start_date_y), "dd/MM/yyyy", null);

            if (string.IsNullOrEmpty(employee_school_view.end_date_d) && string.IsNullOrEmpty(employee_school_view.end_date_m) && string.IsNullOrEmpty(employee_school_view.end_date_y))
            {
                employee_school_view.end_date = null;
                employee_school_view.end_date_d = null;
                employee_school_view.end_date_m = null;
                employee_school_view.end_date_y = null;
            }
            else
            {
                if (string.IsNullOrEmpty(employee_school_view.end_date_d) || employee_school_view.end_date_d == "0")
                {
                    employee_school.end_date_d = "01";
                }
                else if (employee_school_view.end_date_d.Length == 1)
                {
                    employee_school.end_date_d = "0" + employee_school_view.end_date_d;
                }
                else if (Int32.Parse(employee_school_view.end_date_d) > 31)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_school", employee_school_view);
                }
                else
                {
                    employee_school.end_date_d = employee_school_view.end_date_d;
                }
                if (string.IsNullOrEmpty(employee_school_view.end_date_m) || employee_school_view.end_date_m == "0")
                {
                    employee_school.end_date_m = "01";
                }
                else if (employee_school_view.end_date_m.Length == 1)
                {
                    employee_school.end_date_m = "0" + employee_school_view.end_date_m;
                }
                else if (Int32.Parse(employee_school_view.end_date_m) > 12)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_school", employee_school_view);
                }
                else
                {
                    employee_school.end_date_m = employee_school_view.end_date_m;
                }

                if (string.IsNullOrEmpty(employee_school_view.end_date_y) || Int32.Parse(employee_school_view.end_date_y) < 1900)
                {
                    employee_school.end_date_y = "1900";
                }
                else if (employee_school_view.end_date_y.Length > 4 || employee_school_view.end_date_y.Length < 4 || employee_school_view.end_date_y == "0000")
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_school", employee_school_view);
                }
                else
                {
                    employee_school.end_date_y = employee_school_view.end_date_y;
                }
                employee_school.end_date = DateTime.ParseExact((employee_school.end_date_d + "/" + employee_school.end_date_m + "/" + employee_school.end_date_y), "dd/MM/yyyy", null);


            }
            employee_school.diplomas = employee_school_view.diplomas;
            employee_school.modified_date = DateTime.Now;
            employee_school.modified_by = int.Parse(Session["user_id"].ToString());


            employee_school.descriptions = employee_school_view.descriptions;

            h_contentModels.editEmployeeSchool(employee_school);
            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_school_view.employee_id;
            return PartialView("../Shared/control_redirect");
        }

        public ActionResult add_employee_school()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_school(int? id)
        {
            ViewBag.isAdd = true;
            var employee_school_view = new ViewModels.EmployeeSchoolViewModels();
            employee_school_view.employee_id = id;
            employee_school_view.listschool = h_contentModels.getListSchool();
            return PartialView("../Shared/control_detail_employee_school", employee_school_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_school(FormCollection collection)
        {
            var employee_school_view = new ViewModels.EmployeeSchoolViewModels();
            TryUpdateModel(employee_school_view);
            employee_school_view.listschool = h_contentModels.getListSchool();

            web.data.entities.employee_school employee_school = new data.entities.employee_school();
            if (employee_school_view.school_id != null)
            {
                employee_school.school_id = employee_school_view.school_id;
            }
            else
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Vui lòng chọn nhóm trường đào tạo";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            if (string.IsNullOrEmpty(employee_school_view.courses))
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Hãy nhập tên khóa học.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.courses = employee_school_view.courses;
            }
            employee_school.majors = employee_school_view.majors;
            employee_school.study_level = employee_school_view.study_level;
            
            //employee_school.start_date = employee_school_view.start_date;
            if (string.IsNullOrEmpty(employee_school_view.start_date_d) || employee_school_view.start_date_d == "0")
            {
                employee_school.start_date_d = "01";
            }
            else if (employee_school_view.start_date_d.Length == 1)
            {
                employee_school.start_date_d = "0" + employee_school_view.start_date_d;
            }
            else if (Int32.Parse(employee_school_view.start_date_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.start_date_d = employee_school_view.start_date_d;
            }
            if (string.IsNullOrEmpty(employee_school_view.start_date_m) || employee_school_view.start_date_m == "0")
            {
                employee_school.start_date_m = "01";
            }
            else if (employee_school_view.start_date_m.Length == 1)
            {
                employee_school.start_date_m = "0" + employee_school_view.start_date_m;
            }
            else if (Int32.Parse(employee_school_view.start_date_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.start_date_m = employee_school_view.start_date_m;
            }

            if (string.IsNullOrEmpty(employee_school_view.start_date_y) || Int32.Parse(employee_school_view.start_date_y) < 1900)
            {
                employee_school.start_date_y = "1900";
            }
            else if (employee_school_view.start_date_y.Length > 4 || employee_school_view.start_date_y.Length < 4 || employee_school_view.start_date_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
            else
            {
                employee_school.start_date_y = employee_school_view.start_date_y;
            }
            employee_school.start_date = DateTime.ParseExact((employee_school.start_date_d + "/" + employee_school.start_date_m + "/" + employee_school.start_date_y), "dd/MM/yyyy", null);

            //employee_school.end_date = employee_school_view.end_date;
            if (string.IsNullOrEmpty(employee_school_view.end_date_d) && string.IsNullOrEmpty(employee_school_view.end_date_m) && string.IsNullOrEmpty(employee_school_view.end_date_y))
            {
                employee_school_view.end_date = null;
                employee_school_view.end_date_d = null;
                employee_school_view.end_date_m = null;
                employee_school_view.end_date_y = null;
            }
            else {
                if (string.IsNullOrEmpty(employee_school_view.end_date_d) || employee_school_view.end_date_d == "0")
                {
                    employee_school.end_date_d = "01";
                }
                else if (employee_school_view.end_date_d.Length == 1)
                {
                    employee_school.end_date_d = "0" + employee_school_view.end_date_d;
                }
                else if (Int32.Parse(employee_school_view.end_date_d) > 31)
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_school", employee_school_view);
                }
                else
                {
                    employee_school.end_date_d = employee_school_view.end_date_d;
                }
                if (string.IsNullOrEmpty(employee_school_view.end_date_m) || employee_school_view.end_date_m == "0")
                {
                    employee_school.end_date_m = "01";
                }
                else if (employee_school_view.end_date_m.Length == 1)
                {
                    employee_school.end_date_m = "0" + employee_school_view.end_date_m;
                }
                else if (Int32.Parse(employee_school_view.end_date_m) > 12)
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_school", employee_school_view);
                }
                else
                {
                    employee_school.end_date_m = employee_school_view.end_date_m;
                }

                if (string.IsNullOrEmpty(employee_school_view.end_date_y) || Int32.Parse(employee_school_view.end_date_y) < 1900)
                {
                    employee_school.end_date_y = "1900";
                }
                else if (employee_school_view.end_date_y.Length > 4 || employee_school_view.end_date_y.Length < 4 || employee_school_view.end_date_y == "0000")
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_school", employee_school_view);
                }
                else
                {
                    employee_school.end_date_y = employee_school_view.end_date_y;
                }
                employee_school.end_date = DateTime.ParseExact((employee_school.end_date_d + "/" + employee_school.end_date_m + "/" + employee_school.end_date_y), "dd/MM/yyyy", null);

            
            }
            employee_school.diplomas = employee_school_view.diplomas;
            employee_school.created_date = DateTime.Now;
            employee_school.created_by = int.Parse(Session["user_id"].ToString());
            employee_school.descriptions = employee_school_view.descriptions;
            employee_school.employee_id = employee_school_view.employee_id;


            int new_id = h_contentModels.createEmployeeSchool(employee_school);

            if (new_id > 0)
            {

                ViewBag.result_message = "Tạo thành công";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + employee_school_view.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tạo không thành công.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_school", employee_school_view);
            }
        }

        /// <summary>
        /// tbl_leave_manage
        /// </summary>
        /// <returns></returns>

        public ActionResult list_leave_manage()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_leave_manage(int? id, int? employee_id, string text_search)
        {
            return control_list_leave_manage(id ?? 1, 10, employee_id, text_search);
        }
        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_leave_manage(int? id, int? pagesize, int? employee_id, string text_search)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var leave_manage_view = new ViewModels.PageListLeaveManageViewModels();
            id = id ?? 1;
            leave_manage_view.list_pagesize = sizeDrop;
            leave_manage_view.pagesize = pagesize ?? 10;
            leave_manage_view.page_list_leave_manage = h_contentModels.getleave_manageBuilder(id ?? 1, pagesize ?? 10, employee_id, text_search ?? null);
            leave_manage_view.list_type_leave = h_contentModels.listtype_leave();
            leave_manage_view.employeeId = employee_id;
            return PartialView("../Shared/control_list_leave_manage", leave_manage_view);
        }


        public ActionResult edit_leave_manage()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_leave_manage(int? employee_id, int? id)
        {
            ViewBag.isAdd = false;
            var edit_leave_manage_view = new ViewModels.LeaveManageViewModels();
            var edit_leave_manage = h_contentModels.getLeaveManageByID(id ?? 0);
            edit_leave_manage_view.type_leave_id = edit_leave_manage.type_leave_id;
            //edit_leave_manage_view.start_leave = edit_leave_manage.start_leave;
            edit_leave_manage_view.start_leave_d = edit_leave_manage.start_leave_d;
            edit_leave_manage_view.start_leave_m = edit_leave_manage.start_leave_m;
            edit_leave_manage_view.start_leave_y = edit_leave_manage.start_leave_y;
            //edit_leave_manage_view.end_leave = edit_leave_manage.end_leave;
            edit_leave_manage_view.end_leave_y = edit_leave_manage.end_leave_d;
            edit_leave_manage_view.end_leave_m = edit_leave_manage.end_leave_m;
            edit_leave_manage_view.end_leave_y = edit_leave_manage.end_leave_y;
            edit_leave_manage_view.descriptions = edit_leave_manage.descriptions;
            edit_leave_manage_view.employee_id = employee_id;
            edit_leave_manage_view.leave_id = id;
            edit_leave_manage_view.listtype_leave = h_contentModels.getListtype_leave();
            return PartialView("../Shared/control_detail_leave_manage", edit_leave_manage_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_leave_manage(FormCollection collection)
        {
            var leave_manage_view = new ViewModels.LeaveManageViewModels();
            TryUpdateModel(leave_manage_view);
            leave_manage_view.listtype_leave = h_contentModels.getListtype_leave();
            if (string.IsNullOrEmpty(leave_manage_view.descriptions))
            {
                ViewBag.result_message = "Hãy nhập thông tin nghỉ.";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }

            var leave_manage = h_contentModels.getLeaveManageByID(leave_manage_view.leave_id ?? 0);
            if (leave_manage_view.type_leave_id == null)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Hãy chọn loại hình nghỉ.";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }
            else {
                leave_manage.type_leave_id = leave_manage_view.type_leave_id;
            }
            
            //leave_manage.start_leave = leave_manage_view.start_leave;
            if (string.IsNullOrEmpty(leave_manage_view.end_leave_d) || leave_manage_view.end_leave_d == "0")
            {
                leave_manage.end_leave_d = "01";
            }
            else if (leave_manage_view.end_leave_d.Length == 1)
            {
                leave_manage.end_leave_d = "0" + leave_manage_view.end_leave_d;
            }
            else if (Int32.Parse(leave_manage_view.end_leave_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }
            else
            {
                leave_manage.end_leave_d = leave_manage_view.end_leave_d;
            }
            if (string.IsNullOrEmpty(leave_manage_view.end_leave_m) || leave_manage_view.end_leave_m == "0")
            {
                leave_manage.end_leave_m = "01";
            }
            else if (leave_manage_view.end_leave_m.Length == 1)
            {
                leave_manage.end_leave_m = "0" + leave_manage_view.end_leave_m;
            }
            else if (Int32.Parse(leave_manage_view.end_leave_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }
            else
            {
                leave_manage.end_leave_m = leave_manage_view.end_leave_m;
            }

            if (string.IsNullOrEmpty(leave_manage_view.end_leave_y) || Int32.Parse(leave_manage_view.end_leave_y) < 1900)
            {
                leave_manage.end_leave_y = "1900";
            }
            else if (leave_manage_view.end_leave_y.Length > 4 || leave_manage_view.end_leave_y.Length < 4 || leave_manage_view.end_leave_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }
            else
            {
                leave_manage.end_leave_y = leave_manage_view.end_leave_y;
            }
            leave_manage.end_leave = DateTime.ParseExact((leave_manage.end_leave_d + "/" + leave_manage.end_leave_m + "/" + leave_manage.end_leave_y), "dd/MM/yyyy", null);

            //leave_manage.end_leave = leave_manage_view.end_leave;
            if (string.IsNullOrEmpty(leave_manage_view.start_leave_d) || leave_manage_view.start_leave_d == "0")
            {
                leave_manage.start_leave_d = "01";
            }
            else if (leave_manage_view.start_leave_d.Length == 1)
            {
                leave_manage.start_leave_d = "0" + leave_manage_view.start_leave_d;
            }
            else if (Int32.Parse(leave_manage_view.start_leave_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }
            else
            {
                leave_manage.start_leave_d = leave_manage_view.start_leave_d;
            }
            if (string.IsNullOrEmpty(leave_manage_view.start_leave_m) || leave_manage_view.start_leave_m == "0")
            {
                leave_manage.start_leave_m = "01";
            }
            else if (leave_manage_view.start_leave_m.Length == 1)
            {
                leave_manage.start_leave_m = "0" + leave_manage_view.start_leave_m;
            }
            else if (Int32.Parse(leave_manage_view.start_leave_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }
            else
            {
                leave_manage.start_leave_m = leave_manage_view.start_leave_m;
            }

            if (string.IsNullOrEmpty(leave_manage_view.start_leave_y) || Int32.Parse(leave_manage_view.start_leave_y) < 1900)
            {
                leave_manage.start_leave_y = "1900";
            }
            else if (leave_manage_view.start_leave_y.Length > 4 || leave_manage_view.start_leave_y.Length < 4 || leave_manage_view.start_leave_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("/vi/h_content/edit_leave_manage/" + leave_manage_view);
            }
            else
            {
                leave_manage.start_leave_y = leave_manage_view.start_leave_y;
            }
            leave_manage.start_leave = DateTime.ParseExact((leave_manage.start_leave_d + "/" + leave_manage.start_leave_m + "/" + leave_manage.start_leave_y), "dd/MM/yyyy", null);

            leave_manage.descriptions = leave_manage_view.descriptions;

            h_contentModels.editLeaveManage(leave_manage);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_leave_manage/1?employee_id=" + leave_manage.employee_id;
            return PartialView("../Shared/control_redirect");
        }

        public ActionResult add_leave_manage()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_leave_manage(int? id)
        {
            ViewBag.isAdd = true;
            var leave_manage_view = new ViewModels.LeaveManageViewModels();
            leave_manage_view.employee_id = id;
            leave_manage_view.listtype_leave = h_contentModels.getListtype_leave();
            return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_leave_manage(FormCollection collection)
        {
            var leave_manage_view = new ViewModels.LeaveManageViewModels();
            TryUpdateModel(leave_manage_view);
            leave_manage_view.listtype_leave = h_contentModels.getListtype_leave();

            web.data.entities.leave_manage leave_manage = new data.entities.leave_manage();
            if (leave_manage_view.type_leave_id == null)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Hãy chọn loại hình nghỉ.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
            else
            {
                leave_manage.type_leave_id = leave_manage_view.type_leave_id;
            }
            //leave_manage.start_leave = leave_manage_view.start_leave;
            if (string.IsNullOrEmpty(leave_manage_view.start_leave_d) || leave_manage_view.start_leave_d == "0")
            {
                leave_manage.start_leave_d = "01";
            }
            else if (leave_manage_view.start_leave_d.Length == 1)
            {
                leave_manage.start_leave_d = "0" + leave_manage_view.start_leave_d;
            }
            else if (Int32.Parse(leave_manage_view.start_leave_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
            else
            {
                leave_manage.start_leave_d = leave_manage_view.start_leave_d;
            }
            if (string.IsNullOrEmpty(leave_manage_view.start_leave_m) || leave_manage_view.start_leave_m == "0")
            {
                leave_manage.start_leave_m = "01";
            }
            else if (leave_manage_view.start_leave_m.Length == 1)
            {
                leave_manage.start_leave_m = "0" + leave_manage_view.start_leave_m;
            }
            else if (Int32.Parse(leave_manage_view.start_leave_m)>12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
            else
            {
                leave_manage.start_leave_m = leave_manage_view.start_leave_m;
            }

            if (string.IsNullOrEmpty(leave_manage_view.start_leave_y) || Int32.Parse(leave_manage_view.start_leave_y) < 1900)
            {
                leave_manage.start_leave_y = "1900";
            }
            else if (leave_manage_view.start_leave_y.Length > 4 || leave_manage_view.start_leave_y.Length < 4 || leave_manage_view.start_leave_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
            else
            {
                leave_manage.start_leave_y = leave_manage_view.start_leave_y;
            }
            leave_manage.start_leave = DateTime.ParseExact((leave_manage.start_leave_d + "/" + leave_manage.start_leave_m + "/" + leave_manage.start_leave_y), "dd/MM/yyyy", null);

            //leave_manage.end_leave = leave_manage_view.end_leave;
            if (string.IsNullOrEmpty(leave_manage_view.end_leave_d) || leave_manage_view.end_leave_d == "0")
            {
                leave_manage.end_leave_d = "01";
            }
            else if (leave_manage_view.end_leave_d.Length == 1)
            {
                leave_manage.end_leave_d = "0" + leave_manage_view.end_leave_d;
            }
            else if (Int32.Parse(leave_manage_view.end_leave_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày kết thúc nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
            else
            {
                leave_manage.end_leave_d = leave_manage_view.end_leave_d;
            }
            if (string.IsNullOrEmpty(leave_manage_view.end_leave_m) || leave_manage_view.end_leave_m == "0")
            {
                leave_manage.end_leave_m = "01";
            }
            else if (leave_manage_view.end_leave_m.Length == 1)
            {
                leave_manage.end_leave_m = "0" + leave_manage_view.end_leave_m;
            }
            else if ( Int32.Parse(leave_manage_view.end_leave_m) > 2)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng kết thúc nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
            else
            {
                leave_manage.end_leave_m = leave_manage_view.end_leave_m;
            }

            if (string.IsNullOrEmpty(leave_manage_view.end_leave_y) || Int32.Parse(leave_manage_view.end_leave_y) < 1900)
            {
                leave_manage.end_leave_y = "1900";
            }
            else if (leave_manage_view.end_leave_y.Length > 4 || leave_manage_view.end_leave_y.Length < 4 || leave_manage_view.end_leave_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm kết thúc  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
            else
            {
                leave_manage.end_leave_y = leave_manage_view.end_leave_y;
            }
            leave_manage.end_leave = DateTime.ParseExact((leave_manage.end_leave_d + "/" + leave_manage.end_leave_m + "/" + leave_manage.end_leave_y), "dd/MM/yyyy", null);

            leave_manage.descriptions = leave_manage_view.descriptions;
            leave_manage.type_leave_id = leave_manage_view.type_leave_id;
            leave_manage.employee_id = leave_manage_view.employee_id;


            int new_id = h_contentModels.createLeaveManage(leave_manage);

            if (new_id > 0)
            {

                ViewBag.result_message = "Tạo thành công";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_leave_manage/1?employee_id=" + leave_manage_view.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo không thành công.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_leave_manage", leave_manage_view);
            }
        }
        //
        /// <summary>
        /// employee_visa_passport
        /// </summary>
        /// <returns></returns>
        public ActionResult list_employee_visa_passport()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_employee_visa_passport(int? id, int? employeeId, string text_search)
        {
            return control_list_employee_visa_passport(id ?? 1, 10, employeeId, text_search);
        }
        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_employee_visa_passport(int? id, int? pagesize, int? employeeId, string text_search)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var employee_visa_passport_view = new ViewModels.PageListEmployeeVisaPassportViewModels();
            id = id ?? 1;
            employee_visa_passport_view.list_pagesize = sizeDrop;
            employee_visa_passport_view.pagesize = pagesize ?? 10;
            employee_visa_passport_view.page_list_employee_visa_passport = h_contentModels.getemployee_visa_passportBuilder(id ?? 1, pagesize ?? 10, employeeId, text_search ?? null);
            employee_visa_passport_view.list_employee = h_contentModels.listemployee();
            return PartialView("../Shared/control_list_employee_visa_passport", employee_visa_passport_view);
        }

        public ActionResult edit_employee_visa_passport()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_visa_passport(int? employee_id, int? id)
        {
            ViewBag.isAdd = false;
            var employee_visa_passport_view = new ViewModels.EmployeeVisaPassportViewModels();
            var employee_visa_passport = h_contentModels.getEmployeeVisaPassportByID(id ?? 0);
           
                employee_visa_passport_view.passport_id = id;

                employee_visa_passport_view.passport_number = employee_visa_passport.passport_number;
            employee_visa_passport_view.passport_code = employee_visa_passport.passport_code;
            //employee_visa_passport.enable_start = employee_visa_passport_view.enable_start;
            employee_visa_passport_view.passport_issuing_date_d = employee_visa_passport.passport_issuing_date_d;
            employee_visa_passport_view.passport_issuing_date_m = employee_visa_passport.passport_issuing_date_m;
            employee_visa_passport_view.passport_issuing_date_y = employee_visa_passport.passport_issuing_date_y;

            employee_visa_passport.passport_number = employee_visa_passport_view.passport_number;
            employee_visa_passport.passport_issuing_date = employee_visa_passport_view.passport_issuing_date;
            employee_visa_passport_view.enable_end_d = employee_visa_passport.enable_end_d;
            employee_visa_passport_view.enable_end_m = employee_visa_passport.enable_end_m;
            employee_visa_passport_view.enable_end_y = employee_visa_passport.enable_end_y;

            employee_visa_passport.enable_end = employee_visa_passport_view.enable_end;
            employee_visa_passport_view.enable_start_d = employee_visa_passport.enable_start_d;
            employee_visa_passport_view.enable_start_m = employee_visa_passport.enable_start_m;
            employee_visa_passport_view.enable_start_y = employee_visa_passport.enable_start_y;

            employee_visa_passport_view.passport_number = employee_visa_passport.passport_number;
            employee_visa_passport_view.place_of_issue = employee_visa_passport.place_of_issue;
            employee_visa_passport_view.visa_passport_status = employee_visa_passport.visa_passport_status;
            employee_visa_passport_view.created_date = employee_visa_passport.created_date;
            employee_visa_passport_view.created_by = employee_visa_passport.created_by;
            employee_visa_passport_view.modified_date = employee_visa_passport.modified_date;
            employee_visa_passport_view.modified_by = employee_visa_passport.modified_by;
            employee_visa_passport_view.employee_id = employee_id;
            
            return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_visa_passport(FormCollection collection)
        {
            var employee_visa_passport_view = new ViewModels.EmployeeVisaPassportViewModels();
            TryUpdateModel(employee_visa_passport_view);

            if (string.IsNullOrEmpty(employee_visa_passport_view.passport_code))
            {
                ViewBag.result_message = "Hãy nhập mã.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }

            var employee_visa_passport = h_contentModels.getEmployeeVisaPassportByID(employee_visa_passport_view.passport_id ?? 0);

            employee_visa_passport.passport_code = employee_visa_passport_view.passport_code;
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_start_d) || employee_visa_passport_view.enable_start_d == "0")
            {
                employee_visa_passport.enable_start_d = "01";
            }
            else if (employee_visa_passport_view.enable_start_d.Length == 1)
            {
                employee_visa_passport.enable_start_d = "0" + employee_visa_passport_view.enable_start_d;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_start_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_start_d = employee_visa_passport_view.enable_start_d;
            }
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_start_m) || employee_visa_passport_view.enable_start_m == "0")
            {
                employee_visa_passport.enable_start_m = "01";
            }
            else if (employee_visa_passport_view.enable_start_m.Length == 1)
            {
                employee_visa_passport.enable_start_m = "0" + employee_visa_passport_view.enable_start_m;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_start_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_start_m = employee_visa_passport_view.enable_start_m;
            }

            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_start_y) || Int32.Parse(employee_visa_passport_view.enable_start_y) < 1900)
            {
                employee_visa_passport.enable_start_y = "1900";
            }
            else if (employee_visa_passport_view.enable_start_y.Length > 4 || employee_visa_passport_view.enable_start_y.Length < 4 || employee_visa_passport_view.enable_start_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm cấp visa nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_start_y = employee_visa_passport_view.enable_start_y;
            }
            employee_visa_passport.enable_start = DateTime.ParseExact((employee_visa_passport.enable_start_d + "/" + employee_visa_passport.enable_start_m + "/" + employee_visa_passport.enable_start_y), "dd/MM/yyyy", null);

            if (string.IsNullOrEmpty(employee_visa_passport_view.passport_issuing_date_d) || employee_visa_passport_view.passport_issuing_date_d == "0")
            {
                employee_visa_passport.passport_issuing_date_d = "01";
            }
            else if (employee_visa_passport_view.passport_issuing_date_d.Length == 1)
            {
                employee_visa_passport.passport_issuing_date_d = "0" + employee_visa_passport_view.passport_issuing_date_d;
            }
            else if (Int32.Parse(employee_visa_passport_view.passport_issuing_date_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.passport_issuing_date_d = employee_visa_passport_view.passport_issuing_date_d;
            }
            if (string.IsNullOrEmpty(employee_visa_passport_view.passport_issuing_date_m) || employee_visa_passport_view.passport_issuing_date_m == "0")
            {
                employee_visa_passport.passport_issuing_date_m = "01";
            }
            else if (employee_visa_passport_view.passport_issuing_date_m.Length == 1)
            {
                employee_visa_passport.passport_issuing_date_m = "0" + employee_visa_passport_view.passport_issuing_date_m;
            }
            else if (Int32.Parse(employee_visa_passport_view.passport_issuing_date_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.passport_issuing_date_m = employee_visa_passport_view.passport_issuing_date_m;
            }

            if (string.IsNullOrEmpty(employee_visa_passport_view.passport_issuing_date_y) || Int32.Parse(employee_visa_passport_view.passport_issuing_date_y) < 1900)
            {
                employee_visa_passport.passport_issuing_date_y = "1900";
            }
            else if (employee_visa_passport_view.passport_issuing_date_y.Length > 4 || employee_visa_passport_view.passport_issuing_date_y.Length < 4 || employee_visa_passport_view.passport_issuing_date_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm cấp visa nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.passport_issuing_date_y = employee_visa_passport_view.passport_issuing_date_y;
            }
            employee_visa_passport.passport_issuing_date = DateTime.ParseExact((employee_visa_passport.passport_issuing_date_d + "/" + employee_visa_passport.passport_issuing_date_m + "/" + employee_visa_passport.passport_issuing_date_y), "dd/MM/yyyy", null);
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_end_d) || employee_visa_passport_view.enable_end_d == "0")
            {
                employee_visa_passport.enable_end_d = "01";
            }
            else if (employee_visa_passport_view.enable_end_d.Length == 1)
            {
                employee_visa_passport.enable_end_d = "0" + employee_visa_passport_view.enable_end_d;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_end_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_end_d = employee_visa_passport_view.enable_end_d;
            }
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_end_m) || employee_visa_passport_view.enable_end_m == "0")
            {
                employee_visa_passport.enable_end_m = "01";
            }
            else if (employee_visa_passport_view.enable_end_m.Length == 1)
            {
                employee_visa_passport.enable_end_m = "0" + employee_visa_passport_view.enable_end_m;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_end_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_end_m = employee_visa_passport_view.enable_end_m;
            }

            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_end_y) || Int32.Parse(employee_visa_passport_view.enable_end_y) < 1900)
            {
                employee_visa_passport.enable_end_y = "1900";
            }
            else if (employee_visa_passport_view.enable_end_y.Length > 4 || employee_visa_passport_view.enable_end_y.Length < 4 || employee_visa_passport_view.enable_end_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm cấp visa nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_end_y = employee_visa_passport_view.enable_end_y;
            }
            employee_visa_passport.enable_end = DateTime.ParseExact((employee_visa_passport.enable_end_d + "/" + employee_visa_passport.enable_end_m + "/" + employee_visa_passport.enable_end_y), "dd/MM/yyyy", null);

            //employee_visa_passport.enable_start = employee_visa_passport_view.enable_start;
            employee_visa_passport.enable_start_d = employee_visa_passport_view.enable_start_d;
            employee_visa_passport.enable_start_m = employee_visa_passport_view.enable_start_m;
            employee_visa_passport.enable_start_y = employee_visa_passport_view.enable_start_y;
            employee_visa_passport.passport_number = employee_visa_passport_view.passport_number;
            //employee_visa_passport.passport_issuing_date = employee_visa_passport_view.passport_issuing_date;
            employee_visa_passport.passport_issuing_date_d = employee_visa_passport_view.passport_issuing_date_d;
            employee_visa_passport.passport_issuing_date_m = employee_visa_passport_view.passport_issuing_date_m;
            employee_visa_passport.passport_issuing_date_y = employee_visa_passport_view.passport_issuing_date_y;
            //employee_visa_passport.enable_end = employee_visa_passport_view.enable_end;
            employee_visa_passport.enable_end_d = employee_visa_passport_view.enable_end_d;
            employee_visa_passport.enable_end_m = employee_visa_passport_view.enable_end_m;
            employee_visa_passport.enable_end_y = employee_visa_passport_view.enable_end_y;
            employee_visa_passport.place_of_issue = employee_visa_passport_view.place_of_issue;
            employee_visa_passport.visa_passport_status = employee_visa_passport.visa_passport_status;
            employee_visa_passport.modified_date = DateTime.Now;
            employee_visa_passport.modified_by = int.Parse(Session["user_id"].ToString());


            h_contentModels.editEmployeeVisaPassport(employee_visa_passport);


            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_visa_passport.employee_id;
            return PartialView("../Shared/control_redirect");
        }

        public ActionResult add_employee_visa_passport()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_visa_passport(int? id)
        {
            ViewBag.isAdd = true;
            var employee_visa_passport_view = new ViewModels.EmployeeVisaPassportViewModels();
            employee_visa_passport_view.employee_id = id;

            return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_visa_passport(FormCollection collection)
        {
            var employee_visa_passport_view = new ViewModels.EmployeeVisaPassportViewModels();
            TryUpdateModel(employee_visa_passport_view);


            web.data.entities.employee_visa_passport employee_visa_passport = new data.entities.employee_visa_passport();
            employee_visa_passport.passport_code = employee_visa_passport_view.passport_code;

            //employee_visa_passport.enable_start = employee_visa_passport_view.enable_start;
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_start_d) || employee_visa_passport_view.enable_start_d == "0")
            {
                employee_visa_passport.enable_start_d = "01";
            }
            else if (employee_visa_passport_view.enable_start_d.Length == 1)
            {
                employee_visa_passport.enable_start_d = "0" + employee_visa_passport_view.enable_start_d;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_start_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_start_d = employee_visa_passport_view.enable_start_d;
            }
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_start_m) || employee_visa_passport_view.enable_start_m == "0")
            {
                employee_visa_passport.enable_start_m = "01";
            }
            else if (employee_visa_passport_view.enable_start_m.Length == 1)
            {
                employee_visa_passport.enable_start_m = "0" + employee_visa_passport_view.enable_start_m;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_start_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_start_m = employee_visa_passport_view.enable_start_m;
            }

            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_start_y) || Int32.Parse(employee_visa_passport_view.enable_start_y) < 1900)
            {
                employee_visa_passport.enable_start_y = "1900";
            }
            else if (employee_visa_passport_view.enable_start_y.Length > 4 || employee_visa_passport_view.enable_start_y.Length < 4 || employee_visa_passport_view.enable_start_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm cấp visa nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_start_y = employee_visa_passport_view.enable_start_y;
            }
            employee_visa_passport.enable_start = DateTime.ParseExact((employee_visa_passport.enable_start_d + "/" + employee_visa_passport.enable_start_m + "/" + employee_visa_passport.enable_start_y), "dd/MM/yyyy", null);

            employee_visa_passport.passport_number = employee_visa_passport_view.passport_number;
            //employee_visa_passport.passport_issuing_date = employee_visa_passport_view.passport_issuing_date;
            if (string.IsNullOrEmpty(employee_visa_passport_view.passport_issuing_date_d) || employee_visa_passport_view.passport_issuing_date_d == "0")
            {
                employee_visa_passport.passport_issuing_date_d = "01";
            }
            else if (employee_visa_passport_view.passport_issuing_date_d.Length == 1)
            {
                employee_visa_passport.passport_issuing_date_d = "0" + employee_visa_passport_view.passport_issuing_date_d;
            }
            else if (Int32.Parse(employee_visa_passport_view.passport_issuing_date_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.passport_issuing_date_d = employee_visa_passport_view.passport_issuing_date_d;
            }
            if (string.IsNullOrEmpty(employee_visa_passport_view.passport_issuing_date_m) || employee_visa_passport_view.passport_issuing_date_m == "0")
            {
                employee_visa_passport.passport_issuing_date_m = "01";
            }
            else if (employee_visa_passport_view.passport_issuing_date_m.Length == 1)
            {
                employee_visa_passport.passport_issuing_date_m = "0" + employee_visa_passport_view.passport_issuing_date_m;
            }
            else if (Int32.Parse(employee_visa_passport_view.passport_issuing_date_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.passport_issuing_date_m = employee_visa_passport_view.passport_issuing_date_m;
            }

            if (string.IsNullOrEmpty(employee_visa_passport_view.passport_issuing_date_y) || Int32.Parse(employee_visa_passport_view.passport_issuing_date_y) < 1900)
            {
                employee_visa_passport.passport_issuing_date_y = "1900";
            }
            else if (employee_visa_passport_view.passport_issuing_date_y.Length > 4 || employee_visa_passport_view.passport_issuing_date_y.Length < 4 || employee_visa_passport_view.passport_issuing_date_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm cấp visa nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.passport_issuing_date_y = employee_visa_passport_view.passport_issuing_date_y;
            }
            employee_visa_passport.passport_issuing_date = DateTime.ParseExact((employee_visa_passport.passport_issuing_date_d + "/" + employee_visa_passport.passport_issuing_date_m + "/" + employee_visa_passport.passport_issuing_date_y), "dd/MM/yyyy", null);


            //employee_visa_passport.enable_end = employee_visa_passport_view.enable_end;
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_end_d) || employee_visa_passport_view.enable_end_d == "0")
            {
                employee_visa_passport.enable_end_d = "01";
            }
            else if (employee_visa_passport_view.enable_end_d.Length == 1)
            {
                employee_visa_passport.enable_end_d = "0" + employee_visa_passport_view.enable_end_d;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_end_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_end_d = employee_visa_passport_view.enable_end_d;
            }
            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_end_m) || employee_visa_passport_view.enable_end_m == "0")
            {
                employee_visa_passport.enable_end_m = "01";
            }
            else if (employee_visa_passport_view.enable_end_m.Length == 1)
            {
                employee_visa_passport.enable_end_m = "0" + employee_visa_passport_view.enable_end_m;
            }
            else if (Int32.Parse(employee_visa_passport_view.enable_end_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng cấp visanhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_end_m = employee_visa_passport_view.enable_end_m;
            }

            if (string.IsNullOrEmpty(employee_visa_passport_view.enable_end_y) || Int32.Parse(employee_visa_passport_view.enable_end_y) < 1900)
            {
                employee_visa_passport.enable_end_y = "1900";
            }
            else if (employee_visa_passport_view.enable_end_y.Length > 4 || employee_visa_passport_view.enable_end_y.Length < 4 || employee_visa_passport_view.enable_end_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm cấp visa nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
            else
            {
                employee_visa_passport.enable_end_y = employee_visa_passport_view.enable_end_y;
            }
            employee_visa_passport.enable_end = DateTime.ParseExact((employee_visa_passport.enable_end_d + "/" + employee_visa_passport.enable_end_m + "/" + employee_visa_passport.enable_end_y), "dd/MM/yyyy", null);


            employee_visa_passport.place_of_issue = employee_visa_passport_view.place_of_issue;
            employee_visa_passport.visa_passport_status = employee_visa_passport_view.visa_passport_status;

            employee_visa_passport.created_date = DateTime.Now;
            employee_visa_passport.created_by = int.Parse(Session["user_id"].ToString());
            employee_visa_passport.employee_id = employee_visa_passport_view.employee_id;

            int new_id = h_contentModels.createEmployeeVisaPassport(employee_visa_passport);

            if (new_id > 0)
            {

                ViewBag.result_message = "Tạo thành công";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + employee_visa_passport.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo visa/passport lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_visa_passport", employee_visa_passport_view);
            }
        }


        //Kết thúc contronl thủy làm
        //Loại hợp đồng 
        public ActionResult list_type_contract()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_type_contract(int? id, string text_search)
        {
            return control_list_type_contract(id ?? 1, 10, text_search);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_type_contract(int? id, int? pagesize, string text_search)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var type_contract_view = new ViewModels.PageListTypeContractViewModels();
            id = id ?? 1;
            type_contract_view.list_pagesize = sizeDrop;
            type_contract_view.pagesize = pagesize ?? 10;
            type_contract_view.page_list_type_contract = h_contentModels.getPagerTypeContract(id ?? 1, pagesize ?? 10, text_search ?? null);
            return PartialView("../Shared/control_list_type_contract", type_contract_view);
        }

        //Thêm loại hợp đồng
        public ActionResult add_type_contract()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_type_contract(int? id)
        {
            ViewBag.isAdd = true;
            var type_contract_view = new ViewModels.PageListTypeContractViewModels();
            return PartialView("../Shared/control_detail_type_contract", type_contract_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_type_contract(FormCollection collection)
        {
            var type_contract_view = new ViewModels.PageListTypeContractViewModels();
            TryUpdateModel(type_contract_view);

            web.data.entities.type_contract type_contract = new data.entities.type_contract();
            type_contract.type_contract_name = type_contract_view.type_contract_name;
            type_contract.descriptions = type_contract_view.descriptions;

            int new_id = h_contentModels.createTypeContract(type_contract);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo loại hợp đồng thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_type_contract";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo loại hợp đồng lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_type_contract", type_contract_view);
            }
        }

        // Sửa loại hợp đồng
        public ActionResult edit_type_contract()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_type_contract(int? id)
        {
            ViewBag.isAdd = false;
            var type_contract_view = new ViewModels.PageListTypeContractViewModels();
            var type_contract = h_contentModels.getTypeContractByID(id ?? 0);
            if (type_contract != null) {
                type_contract_view.type_contract_id = type_contract.type_contract_id;
                type_contract_view.type_contract_name = type_contract.type_contract_name;
                type_contract_view.descriptions = type_contract.descriptions;
            }
            

            return PartialView("../Shared/control_detail_type_contract", type_contract_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_type_contract(FormCollection collection)
        {
            var type_contract_view = new ViewModels.PageListTypeContractViewModels();
            TryUpdateModel(type_contract_view);

            if (string.IsNullOrEmpty(type_contract_view.type_contract_name))
            {
                ViewBag.result_message = "Nhập tên loại hợp đồng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_type_contract", type_contract_view);
            }

            var type_contract = h_contentModels.getTypeContractByID(type_contract_view.type_contract_id ?? 0);
            type_contract.type_contract_id = (int)type_contract_view.type_contract_id;
            type_contract.type_contract_name = type_contract_view.type_contract_name;
            type_contract.descriptions = type_contract_view.descriptions;


            h_contentModels.editTypeContract(type_contract);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_type_contract";
            return PartialView("../Shared/control_redirect");
        }

        

        //Loại hình nghỉ 
        public ActionResult list_type_leave()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_type_leave(int? id, string text_search)
        {
            return control_list_type_leave(id ?? 1, 10, text_search);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_type_leave(int? id, int? pagesize, string text_search)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var type_leave_view = new ViewModels.PageListTypeLeaveViewModels();
            id = id ?? 1;
            type_leave_view.list_pagesize = sizeDrop;
            type_leave_view.pagesize = pagesize ?? 10;
            type_leave_view.page_list_type_leave = h_contentModels.getPagerTypeLeave(id ?? 1, pagesize ?? 10, text_search ?? null);
            return PartialView("../Shared/control_list_type_leave", type_leave_view);
        }

        //Thêm loại hợp đồng
        public ActionResult add_type_leave()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_type_leave(int? id)
        {
            ViewBag.isAdd = true;
            var type_leave_view = new ViewModels.PageListTypeLeaveViewModels();
            return PartialView("../Shared/control_detail_type_leave", type_leave_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_type_leave(FormCollection collection)
        {
            var type_leave_view = new ViewModels.PageListTypeLeaveViewModels();
            TryUpdateModel(type_leave_view);

            web.data.entities.type_leave type_leave = new data.entities.type_leave();
            type_leave.type_leave_name = type_leave_view.type_leave_name;
            type_leave.descriptions = type_leave_view.descriptions;

            int new_id = h_contentModels.createTypeLeave(type_leave);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo loại hợp đồng thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_type_leave";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo loại hợp đồng lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_type_leave", type_leave_view);
            }
        }

        // Sửa loại hợp đồng
        public ActionResult edit_type_leave()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_type_leave(int? id)
        {
            ViewBag.isAdd = false;
            var type_leave_view = new ViewModels.PageListTypeLeaveViewModels();
            var type_leave = h_contentModels.getTypeLeaveByID(id ?? 0);
            if (type_leave != null)
            {
                type_leave_view.type_leave_id = type_leave.type_leave_id;
                type_leave_view.type_leave_name = type_leave.type_leave_name;
                type_leave_view.descriptions = type_leave.descriptions;
            }


            return PartialView("../Shared/control_detail_type_leave", type_leave_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_type_leave(FormCollection collection)
        {
            var type_leave_view = new ViewModels.PageListTypeLeaveViewModels();
            TryUpdateModel(type_leave_view);

            if (string.IsNullOrEmpty(type_leave_view.type_leave_name))
            {
                ViewBag.result_message = "Nhập tên loại hợp đồng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_type_leave", type_leave_view);
            }

            var type_leave = h_contentModels.getTypeLeaveByID(type_leave_view.type_leave_id ?? 0);
            type_leave.type_leave_id = (int)type_leave_view.type_leave_id;
            type_leave.type_leave_name = type_leave_view.type_leave_name;
            type_leave.descriptions = type_leave_view.descriptions;


            h_contentModels.editTypeLeave(type_leave);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_type_leave";
            return PartialView("../Shared/control_redirect");
        }

        // Thêm Thân nhân
        public ActionResult add_employee_family()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_family(int? id)
        {
            ViewBag.isAdd = true;
            var employee_family_view = new ViewModels.EmployeeFamilyViewModels();
            employee_family_view.employee_id = id;
            return PartialView("../Shared/control_detail_employee_family", employee_family_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_family(FormCollection collection)
        {
            var employee_family_view = new ViewModels.EmployeeFamilyViewModels();
            TryUpdateModel(employee_family_view);

            web.data.entities.employee_family employee_family = new data.entities.employee_family();
            employee_family.employee_id = employee_family_view.employee_id;            
            employee_family.files = employee_family_view.files;
            employee_family.fullname = employee_family_view.fullname;
            employee_family.hometown = employee_family_view.hometown;
            employee_family.current_address = employee_family_view.current_address;
            if (employee_family_view.birth_day.Length > 4 || employee_family_view.birth_day.Length < 4)
            {
                ViewBag.result_message = "Năm sinh chưa đúng định dạng YYYY.Xin vui lòng nhập lại.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_family", employee_family_view);
            }
            else {
                employee_family.birth_day = employee_family_view.birth_day;
            }

            if (employee_family_view.obj_family != null && employee_family_view.obj_family > 0)
            {
                employee_family.obj_family = employee_family_view.obj_family;
            }
            else
            {
                ViewBag.result_message = "Xin chọn đối tượng thân nhân !";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_family", employee_family_view);
            }


            employee_family.job = employee_family_view.job;
            
            employee_family.family_status = employee_family_view.family_status;
            employee_family.created_date = DateTime.Now ;
            employee_family.created_by = int.Parse(Session["user_id"].ToString());

            
            int new_id = h_contentModels.createEmployeeFamily(employee_family);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo thân nhân thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + employee_family.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo thân nhân lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_family", employee_family_view);
            }
        }

        //Sửa thân nhân
       
        public ActionResult edit_employee_family()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_family(int? employee_id, int? id)
        {
            ViewBag.isAdd = false;
            var employee_family_view = new ViewModels.EmployeeFamilyViewModels();
            var employee_family = h_contentModels.getEmployeeFamilyByID(id ?? 0);
            if (employee_family != null)
            {
                employee_family_view.family_id = employee_family.family_id;
                employee_family_view.employee_id = employee_id;
                employee_family_view.files = employee_family.files;
                employee_family_view.fullname = employee_family.fullname;
                employee_family_view.hometown = employee_family.hometown;
                employee_family_view.current_address = employee_family.current_address;
                employee_family_view.birth_day = employee_family.birth_day;
                employee_family_view.job = employee_family.job;
                employee_family_view.obj_family = employee_family.obj_family;
                employee_family_view.family_status = employee_family.family_status;
                employee_family_view.modified_date = DateTime.Now;
                employee_family_view.modified_by = int.Parse(Session["user_id"].ToString());
            }


            return PartialView("../Shared/control_detail_employee_family", employee_family_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_family(FormCollection collection)
        {
            var employee_family_view = new ViewModels.EmployeeFamilyViewModels();
            TryUpdateModel(employee_family_view);

            //if (string.IsNullOrEmpty(employee_family_view.files))
            //{
            //    ViewBag.result_message = "Nhập hồ sơ thân nhân.";
            //    ViewBag.result = false;
            //    return PartialView("../Shared/control_detail_employee_family", employee_family_view);
            //}

            var employee_family = h_contentModels.getEmployeeFamilyByID(employee_family_view.family_id ?? 0);
            employee_family.family_id = (int)employee_family_view.family_id;
            employee_family.employee_id = employee_family_view.employee_id;
            employee_family.files = employee_family_view.files;
            employee_family.fullname = employee_family_view.fullname;
            employee_family.hometown = employee_family_view.hometown;
            employee_family.current_address = employee_family_view.current_address;
            employee_family.job = employee_family_view.job;
            employee_family.family_status = employee_family_view.family_status;
            employee_family.modified_date = DateTime.Now;
            employee_family.modified_by = int.Parse(Session["user_id"].ToString());
            if (employee_family_view.obj_family != null && employee_family_view.obj_family > 0)
            {
                employee_family.obj_family = employee_family_view.obj_family;
            }
            else
            {
                ViewBag.result_message = "Xin chọn đối tượng thân nhân !";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_family", employee_family_view);
            }

            if (employee_family_view.birth_day.Length > 4 || employee_family_view.birth_day.Length < 4)
            {
                ViewBag.result_message = "Năm sinh chưa đúng định dạng YYYY.Xin vui lòng nhập lại.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_family", employee_family_view);
            }
            else
            {
                employee_family.birth_day = employee_family_view.birth_day;
            }

            h_contentModels.editEmployeeFamily(employee_family);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_family.employee_id;
            return PartialView("../Shared/control_redirect");
        }


        // Thêm hồ sơ bảo hiểm
        public ActionResult add_employee_insurance()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_insurance(int? id)
        {
            ViewBag.isAdd = true;
            var employee_insurance_view = new ViewModels.EmployeeInsuranceViewModels();
            employee_insurance_view.employee_id = id;
            return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_insurance(FormCollection collection)
        {
            var employee_insurance_view = new ViewModels.EmployeeInsuranceViewModels();
            TryUpdateModel(employee_insurance_view);

            web.data.entities.employee_insurance employee_insurance = new data.entities.employee_insurance();
            employee_insurance.employee_id = employee_insurance_view.employee_id;
            //employee_insurance.start_date = employee_insurance_view.start_date;
            if (string.IsNullOrEmpty(employee_insurance_view.start_date_d) || employee_insurance_view.start_date_d == "0")
            {
                employee_insurance.start_date_d = "01";
            }
            else if (employee_insurance_view.start_date_d.Length == 1)
            {
                employee_insurance.start_date_d = "0" + employee_insurance_view.start_date_d;
            }
            else if (Int32.Parse(employee_insurance_view.start_date_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày tạo hồ  sơ bảo hiểm nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
            }
            else
            {
                employee_insurance.start_date_d = employee_insurance_view.start_date_d;
            }
            if (string.IsNullOrEmpty(employee_insurance_view.start_date_m) || employee_insurance_view.start_date_m == "0")
            {
                employee_insurance.start_date_m = "01";
            }
            else if (employee_insurance_view.start_date_m.Length == 1)
            {
                employee_insurance.start_date_m = "0" + employee_insurance_view.start_date_m;
            }
            else if (Int32.Parse(employee_insurance_view.start_date_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng tạo hồ  sơ bảo hiểm nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
            }
            else
            {
                employee_insurance.start_date_m = employee_insurance_view.start_date_m;
            }

            if (string.IsNullOrEmpty(employee_insurance_view.start_date_y) || Int32.Parse(employee_insurance_view.start_date_y) < 1900)
            {
                employee_insurance.start_date_y = "1900";
            }
            else if (employee_insurance_view.start_date_y.Length > 4 || employee_insurance_view.start_date_y.Length < 4 || employee_insurance_view.start_date_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm tạo hồ  sơ bảo hiểm  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
            }
            else
            {
                employee_insurance.start_date_y = employee_insurance_view.start_date_y;
            }
            employee_insurance.start_date = DateTime.ParseExact((employee_insurance.start_date_d + "/" + employee_insurance.start_date_m + "/" + employee_insurance.start_date_y), "dd/MM/yyyy", null);

            employee_insurance.content = employee_insurance_view.content;
            employee_insurance.premium = employee_insurance_view.premium;
            employee_insurance.number_insurance_book = employee_insurance_view.number_insurance_book;
            employee_insurance.insurance_status = employee_insurance_view.insurance_status;
            employee_insurance.insurance_status = employee_insurance_view.insurance_status;
            employee_insurance.created_date = DateTime.Now;
            employee_insurance.created_by = int.Parse(Session["user_id"].ToString());


            int new_id = h_contentModels.createEmployeeInsurance(employee_insurance);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo hồ sơ bảo hiểm thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + employee_insurance.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo hồ sơ bảo hiểm lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
            }
        }

        //Sửa hồ bảo hiểm
        public ActionResult edit_employee_insurance()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_insurance(int? employee_id, int? id)
        {
            ViewBag.isAdd = false;
            var employee_insurance_view = new ViewModels.EmployeeInsuranceViewModels();
            var employee_insurance = h_contentModels.getEmployeeInsuranceByID(id ?? 0);
            if (employee_insurance != null)
            {
                employee_insurance_view.insurance_id = employee_insurance.insurance_id;
                employee_insurance_view.employee_id = employee_id;
                //employee_insurance_view.start_date = employee_insurance.start_date;
                employee_insurance_view.start_date_d = employee_insurance.start_date_d;
                employee_insurance_view.start_date_m = employee_insurance.start_date_m;
                employee_insurance_view.start_date_y = employee_insurance.start_date_y;

                employee_insurance_view.content = employee_insurance.content;
                employee_insurance_view.premium = employee_insurance.premium;
                employee_insurance_view.insurance_status = employee_insurance.insurance_status ?? 0;
                employee_insurance_view.number_insurance_book = employee_insurance.number_insurance_book;
                employee_insurance_view.insurance_status = employee_insurance.insurance_status;
                employee_insurance_view.modified_date = DateTime.Now;
                employee_insurance_view.modified_by = int.Parse(Session["user_id"].ToString());
            }


            return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_insurance(FormCollection collection)
        {
            var employee_insurance_view = new ViewModels.EmployeeInsuranceViewModels();
            TryUpdateModel(employee_insurance_view);


            var employee_insurance = h_contentModels.getEmployeeInsuranceByID(employee_insurance_view.insurance_id ?? 0);
            employee_insurance.insurance_id = (int)employee_insurance_view.insurance_id;
            employee_insurance.employee_id = employee_insurance_view.employee_id;
            //employee_insurance.start_date = employee_insurance_view.start_date;
            if (string.IsNullOrEmpty(employee_insurance_view.start_date_d) || employee_insurance_view.start_date_d == "0")
            {
                employee_insurance.start_date_d = "01";
            }
            else if (employee_insurance_view.start_date_d.Length == 1)
            {
                employee_insurance.start_date_d = "0" + employee_insurance_view.start_date_d;
            }
            else if (Int32.Parse(employee_insurance_view.start_date_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày tạo hồ  sơ bảo hiểm nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
            }
            else
            {
                employee_insurance.start_date_d = employee_insurance_view.start_date_d;
            }
            if (string.IsNullOrEmpty(employee_insurance_view.start_date_m) || employee_insurance_view.start_date_m == "0")
            {
                employee_insurance.start_date_m = "01";
            }
            else if (employee_insurance_view.start_date_m.Length == 1)
            {
                employee_insurance.start_date_m = "0" + employee_insurance_view.start_date_m;
            }
            else if (Int32.Parse(employee_insurance_view.start_date_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng tạo hồ  sơ bảo hiểm nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
            }
            else
            {
                employee_insurance.start_date_m = employee_insurance_view.start_date_m;
            }

            if (string.IsNullOrEmpty(employee_insurance_view.start_date_y) || Int32.Parse(employee_insurance_view.start_date_y) < 1900)
            {
                employee_insurance.start_date_y = "1900";
            }
            else if (employee_insurance_view.start_date_y.Length > 4 || employee_insurance_view.start_date_y.Length < 4 || employee_insurance_view.start_date_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm tạo hồ  sơ bảo hiểm  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_insurance", employee_insurance_view);
            }
            else
            {
                employee_insurance.start_date_y = employee_insurance_view.start_date_y;
            }
            employee_insurance.start_date = DateTime.ParseExact((employee_insurance.start_date_d + "/" + employee_insurance.start_date_m + "/" + employee_insurance.start_date_y), "dd/MM/yyyy", null);


            employee_insurance.content = employee_insurance_view.content;
            employee_insurance.premium = employee_insurance_view.premium;
            employee_insurance.number_insurance_book = employee_insurance_view.number_insurance_book;
            employee_insurance.insurance_status = employee_insurance_view.insurance_status;
            employee_insurance.modified_date = DateTime.Now;
            employee_insurance.modified_by = int.Parse(Session["user_id"].ToString());


            h_contentModels.editEmployeeInsurance(employee_insurance);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/"+employee_insurance_view.employee_id;
            return PartialView("../Shared/control_redirect");
        }



        // Thêm hồ công tác
        public ActionResult add_employee_rotation()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_rotation(int? id)
        {
            ViewBag.isAdd = true;
            var employee_rotation_view = new ViewModels.EmployeeRotationViewModels();
            employee_rotation_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            employee_rotation_view.employee_id = id;
            return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_rotation(FormCollection collection)
        {
            var employee_rotation_view = new ViewModels.EmployeeRotationViewModels();
            TryUpdateModel(employee_rotation_view);
            employee_rotation_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            web.data.entities.employee_rotation employee_rotation = new data.entities.employee_rotation();
            employee_rotation.employee_id = employee_rotation_view.employee_id;
           // employee_rotation.years = employee_rotation_view.years;
            //employee_rotation.from_date = employee_rotation_view.from_date;
            if (string.IsNullOrEmpty(employee_rotation_view.from_date_d) || employee_rotation_view.from_date_d == "0")
            {
                employee_rotation.from_date_d = "01";
            }
            else if (employee_rotation_view.from_date_d.Length == 1)
            {
                employee_rotation.from_date_d = "0" + employee_rotation_view.from_date_d;
            }
            else if (Int32.Parse(employee_rotation_view.from_date_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.from_date_d = employee_rotation_view.from_date_d;
            }
            if (string.IsNullOrEmpty(employee_rotation_view.from_date_m) || employee_rotation_view.from_date_m == "0")
            {
                employee_rotation.from_date_m = "01";
            }
            else if (employee_rotation_view.from_date_m.Length == 1)
            {
                employee_rotation.from_date_m = "0" + employee_rotation_view.from_date_m;
            }
            else if (Int32.Parse(employee_rotation_view.from_date_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.from_date_m = employee_rotation_view.from_date_m;
            }

            if (string.IsNullOrEmpty(employee_rotation_view.from_date_y)||Int32.Parse(employee_rotation_view.from_date_y)<1900)
            {
                employee_rotation.from_date_y = "1900";
            }
            else if (employee_rotation_view.from_date_y.Length > 4 || employee_rotation_view.from_date_y.Length < 4 || employee_rotation_view.from_date_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.from_date_y = employee_rotation_view.from_date_y;
            }
            employee_rotation.from_date = DateTime.ParseExact((employee_rotation.from_date_d + "/" + employee_rotation.from_date_m + "/" + employee_rotation.from_date_y), "dd/MM/yyyy", null);

            //employee_rotation.to_date = employee_rotation_view.to_date;
            if (string.IsNullOrEmpty(employee_rotation_view.to_date_d) && string.IsNullOrEmpty(employee_rotation_view.to_date_m) && string.IsNullOrEmpty(employee_rotation_view.to_date_y))
            {
                employee_rotation.to_date = null;
                employee_rotation.to_date_d = null;
                employee_rotation.to_date_m = null;
                employee_rotation.to_date_y = null;
            }
            else {

                if (string.IsNullOrEmpty(employee_rotation_view.to_date_d) || employee_rotation_view.to_date_d == "0")
                {
                    employee_rotation.to_date_d = "01";
                }
                else if (employee_rotation_view.to_date_d.Length == 1)
                {
                    employee_rotation.to_date_d = "0" + employee_rotation_view.to_date_d;
                }
                else if (Int32.Parse(employee_rotation_view.to_date_d) > 31)
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
                }
                else
                {
                    employee_rotation.to_date_d = employee_rotation_view.to_date_d;
                }
                if (string.IsNullOrEmpty(employee_rotation_view.to_date_m) || employee_rotation_view.to_date_m == "0")
                {
                    employee_rotation.to_date_m = "01";
                }
                else if (employee_rotation_view.to_date_m.Length == 1)
                {
                    employee_rotation.to_date_m = "0" + employee_rotation_view.to_date_m;
                }
                else if (Int32.Parse(employee_rotation_view.to_date_m) > 12)
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
                }
                else
                {
                    employee_rotation.to_date_m = employee_rotation_view.to_date_m;
                }

                if (string.IsNullOrEmpty(employee_rotation_view.to_date_y)|| Int32.Parse(employee_rotation_view.to_date_y)<1900)
                {
                    employee_rotation.to_date_y = "1900";
                }
                else if (employee_rotation_view.to_date_y.Length > 4 || employee_rotation_view.to_date_y.Length < 4 || employee_rotation_view.to_date_y == "0000")
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
                }
                else
                {
                    employee_rotation.to_date_y = employee_rotation_view.to_date_y;
                }
                employee_rotation.to_date = DateTime.ParseExact((employee_rotation.to_date_d + "/" + employee_rotation.to_date_m + "/" + employee_rotation.to_date_y), "dd/MM/yyyy", null);

            }

            employee_rotation.levels = employee_rotation_view.levels;
            employee_rotation.positions = employee_rotation_view.positions;
            employee_rotation.branch = employee_rotation_view.branch;
            //employee_rotation.unit = employee_rotation_view.unit;
            employee_rotation.rotation_status = employee_rotation_view.rotation_status;
            employee_rotation.created_date = DateTime.Now;
            employee_rotation.created_by = int.Parse(Session["user_id"].ToString());
            if (employee_rotation_view.departments_id != null)
                {

                    employee_rotation.departments_id = employee_rotation_view.departments_id;
                }
            else
            {
                ViewBag.result_message = "Xin chọn lại phòng ban";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }

            int new_id = h_contentModels.createEmployeeRotation(employee_rotation);

            if (new_id > 0)
            {
                
                
                ViewBag.result_message = "Tạo hồ sơ công tác thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + employee_rotation_view.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo hồ sơ công tác lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
        }

        //cập nhật hồ sơ công tác
        public ActionResult edit_employee_rotation()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_rotation(int? employee_id, int? id)
        {
            ViewBag.isAdd = false;
            var employee_rotation_view = new ViewModels.EmployeeRotationViewModels();
            var employee_rotation = h_contentModels.getEmployeeRotationByID(id ?? 0);
                employee_rotation_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            if (employee_rotation != null)
            {
                employee_rotation_view.rotation_id = employee_rotation.rotation_id;
                employee_rotation_view.employee_id = employee_id;
                //employee_rotation_view.years = employee_rotation.years;
                //employee_rotation_view.from_date = employee_rotation.from_date;
                employee_rotation_view.from_date_d = employee_rotation.from_date_d;
                employee_rotation_view.from_date_m = employee_rotation.from_date_m;
                employee_rotation_view.from_date_y = employee_rotation.from_date_y;
                //employee_rotation_view.to_date = employee_rotation.to_date;
                employee_rotation_view.to_date_y = employee_rotation.to_date_d;
                employee_rotation_view.to_date_m = employee_rotation.to_date_m;
                employee_rotation_view.to_date_y = employee_rotation.to_date_y;

                employee_rotation_view.branch = employee_rotation.branch;
                employee_rotation_view.departments_id = employee_rotation.departments_id;
                employee_rotation_view.levels = employee_rotation.levels;
                employee_rotation_view.positions = employee_rotation.positions;
                employee_rotation_view.unit = employee_rotation.unit!=null?employee_rotation.unit.ToString():"";
                employee_rotation_view.rotation_status = employee_rotation.rotation_status ?? 0;                
                employee_rotation_view.modified_date = DateTime.Now;
                employee_rotation_view.modified_by = int.Parse(Session["user_id"].ToString());
            }


            return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_rotation(FormCollection collection)
        {
            var employee_rotation_view = new ViewModels.EmployeeRotationViewModels();
            TryUpdateModel(employee_rotation_view);
            employee_rotation_view.list_department = h_contentModels.getListDepartmentsBuilder(null);

            var employee_rotation = h_contentModels.getEmployeeRotationByID(employee_rotation_view.rotation_id ?? 0);
            employee_rotation.rotation_id = (int)employee_rotation_view.rotation_id;
            employee_rotation.employee_id = employee_rotation_view.employee_id;
            //employee_rotation.years = employee_rotation_view.years;
            if (string.IsNullOrEmpty(employee_rotation_view.from_date_d) || employee_rotation_view.from_date_d == "0")
            {
                employee_rotation.from_date_d = "01";
            }
            else if (employee_rotation_view.from_date_d.Length == 1)
            {
                employee_rotation.from_date_d = "0" + employee_rotation_view.from_date_d;
            }
            else if (Int32.Parse(employee_rotation_view.from_date_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.from_date_d = employee_rotation_view.from_date_d;
            }
            if (string.IsNullOrEmpty(employee_rotation_view.from_date_m) || employee_rotation_view.from_date_m == "0")
            {
                employee_rotation.from_date_m = "01";
            }
            else if (employee_rotation_view.from_date_m.Length == 1)
            {
                employee_rotation.from_date_m = "0" + employee_rotation_view.from_date_m;
            }
            else if (Int32.Parse(employee_rotation_view.from_date_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.from_date_m = employee_rotation_view.from_date_m;
            }

            if (string.IsNullOrEmpty(employee_rotation_view.from_date_y) || Int32.Parse(employee_rotation_view.from_date_y)<1900)
            {
                employee_rotation.from_date_y = "1900";
            }
            else if (employee_rotation_view.from_date_y.Length > 4 || employee_rotation_view.from_date_y.Length < 4 || employee_rotation_view.from_date_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.from_date_y = employee_rotation_view.from_date_y;
            }
            employee_rotation.from_date = DateTime.ParseExact((employee_rotation.from_date_d + "/" + employee_rotation.from_date_m + "/" + employee_rotation.from_date_y), "dd/MM/yyyy", null);

            //employee_rotation.to_date = employee_rotation_view.to_date;
            if (string.IsNullOrEmpty(employee_rotation_view.to_date_d) || employee_rotation_view.to_date_d == "0")
            {
                employee_rotation.to_date_d = "01";
            }
            else if (employee_rotation_view.to_date_d.Length == 1)
            {
                employee_rotation.to_date_d = "0" + employee_rotation_view.to_date_d;
            }
            else if (Int32.Parse(employee_rotation_view.to_date_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.to_date_d = employee_rotation_view.to_date_d;
            }
            if (string.IsNullOrEmpty(employee_rotation_view.to_date_m) || employee_rotation_view.to_date_m == "0")
            {
                employee_rotation.to_date_m = "01";
            }
            else if (employee_rotation_view.to_date_m.Length == 1)
            {
                employee_rotation.to_date_m = "0" + employee_rotation_view.to_date_m;
            }
            else if (Int32.Parse(employee_rotation_view.to_date_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng bắt đầu nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.to_date_m = employee_rotation_view.to_date_m;
            }

            if (string.IsNullOrEmpty(employee_rotation_view.to_date_y)|| Int32.Parse(employee_rotation_view.from_date_y)<1900)
            {
                employee_rotation.to_date_y = "1900";
            }
            else if (employee_rotation_view.to_date_y.Length > 4 || employee_rotation_view.to_date_y.Length < 4 || employee_rotation_view.to_date_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm bắt đầu  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_rotation", employee_rotation_view);
            }
            else
            {
                employee_rotation.to_date_y = employee_rotation_view.to_date_y;
            }
            employee_rotation.to_date = DateTime.ParseExact((employee_rotation.to_date_d + "/" + employee_rotation.to_date_m + "/" + employee_rotation.to_date_y), "dd/MM/yyyy", null);

            employee_rotation.levels = employee_rotation_view.levels;
            employee_rotation.branch = employee_rotation_view.branch;
            employee_rotation.departments_id = employee_rotation_view.employee_id;
            employee_rotation.positions = employee_rotation_view.positions;
            employee_rotation.unit = employee_rotation_view.unit;
            employee_rotation.rotation_status = employee_rotation_view.rotation_status;
            employee_rotation.modified_date = DateTime.Now;
            employee_rotation.modified_by = int.Parse(Session["user_id"].ToString());

            h_contentModels.editEmployeeRotation(employee_rotation);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_rotation.employee_id;
            return PartialView("../Shared/control_redirect");
        }

       
        // Thêm hồ sơ 
        public ActionResult add_employee()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee(int? id)
        {
            ViewBag.isAdd = true;
            var employee_view = new ViewModels.EmployeeViewModels();
            employee_view.employee_id = id;
            employee_view.employee_status = 1;
            //employee_view.list_department = h_contentModels.getListDepartment();
           // employee_view.list_obj_employee = h_contentModels.getListObjEmployee();
            employee_view.list_obj_employee = h_contentModels.getListobject_employeeBuilder(null);
            employee_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            if (id != null)
            {
                employee_view.departments_id = id;
            }
            if (id != null)
            {
                employee_view.object_employee_id = id;
            }
            return PartialView("../Shared/control_detail_employee", employee_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee(FormCollection collection)
        {
            var employee_view = new ViewModels.EmployeeViewModels();
            TryUpdateModel(employee_view,collection.ToValueProvider());
            
            employee_view.list_obj_employee = h_contentModels.getListobject_employeeBuilder(null);
            employee_view.list_department = h_contentModels.getListDepartmentsBuilder(null);

            web.data.entities.employee employee = new data.entities.employee();
            employee.employee_code = employee_view.employee_code;
            employee.full_name = employee_view.full_name;
            
            //if (employee.birth_day != null)
            //{
            //    employee.b_day = employee_view.birth_day.Value.Day;
            //    employee.b_month = employee_view.birth_day.Value.Month;
            //    employee.b_year = employee_view.birth_day.Value.Year;
            //}

            //employee.birth_day = employee_view.birth_day;
            
            if(employee_view.b_day==null){
                employee.b_day = 01;
            }
            else if (employee_view.b_day > 31 || employee_view.b_day == 0)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày sinh nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else {
                employee.b_day = employee_view.b_day;
            }
            //thangs sinh
            if (employee_view.b_month == null)
            {
                employee.b_month = 01;
            }
            else if (employee_view.b_month == 0 || employee_view.b_month > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng sinh nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.b_month = employee_view.b_month;
            }

            //năm sinh
            if (employee_view.b_year == null || employee_view.b_year < 1900)
            {
                employee.b_year = 1900;
            }
            else
            {
                employee.b_year = employee_view.b_year;
            }
            employee.birth_day = DateTime.ParseExact(string.Format("{0:00}", employee.b_day) + "/" + string.Format("{0:00}", employee.b_month) + "/" + employee.b_year, "dd/MM/yyyy", null);

            employee.phone = employee_view.phone;
            employee.email = employee_view.email;
            employee.gender = employee_view.gender;
            employee.family_reduction = employee_view.family_reduction;
            employee.hometown = employee_view.hometown;
            employee.current_address = employee_view.current_address;
            employee.household_registration = employee_view.household_registration;


            //Ngày vào đoàn
            if (string.IsNullOrEmpty(employee_view.dateIn_doan_d)||employee_view.dateIn_doan_d == "0") {
                employee.dateIn_doan_d = "01";
            }
            else if (employee_view.dateIn_doan_d.Length == 1) {
                employee.dateIn_doan_d = "0" + employee_view.dateIn_doan_d; 
            }
            else if (Int32.Parse(employee_view.dateIn_doan_d) > 31 )
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày vào đoàn nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else {
                employee.dateIn_doan_d = employee_view.dateIn_doan_d; 
            }
            if (string.IsNullOrEmpty(employee_view.dateIn_doan_m) || employee_view.dateIn_doan_m == "0")
            {
                employee.dateIn_doan_m = "01";
            }
            else if (employee_view.dateIn_doan_m.Length == 1) {
                employee.dateIn_doan_m = "0" + employee_view.dateIn_doan_m;
            }
            else if (Int32.Parse(employee_view.dateIn_doan_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng vào đoàn  nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else { 
                employee.dateIn_doan_m = employee_view.dateIn_doan_m; 
            }

            if (string.IsNullOrEmpty(employee_view.dateIn_doan_y)||Int32.Parse(employee_view.dateIn_doan_y)<1900)
            {
                employee.dateIn_doan_y = "1900";
            }
            else if (employee_view.dateIn_doan_y.Length > 4 || employee_view.dateIn_doan_y.Length < 4 || employee_view.dateIn_doan_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng vào đoàn nhập chưa đúng";
                ViewBag.result_message = "Năm nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else { 
                employee.dateIn_doan_y = employee_view.dateIn_doan_y; 
            }
            employee.dateIn_doan = DateTime.ParseExact((employee.dateIn_doan_d + "/" + employee.dateIn_doan_m + "/" + employee.dateIn_doan_y),"dd/MM/yyyy",null);


            ////Ngày vào đảng
            if (string.IsNullOrEmpty(employee_view.dateIn_dang_d) || employee_view.dateIn_dang_d == "0")
            {
                employee.dateIn_dang_d = "01";
            }
            else if (employee_view.dateIn_dang_d.Length == 1)
            {
                employee.dateIn_dang_d = "0" + employee_view.dateIn_dang_d;
            }
            else if (Int32.Parse(employee_view.dateIn_dang_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày vào đảng nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_dang_d = employee_view.dateIn_dang_d;
            }
            if (string.IsNullOrEmpty(employee_view.dateIn_dang_m) || employee_view.dateIn_dang_m == "0")
            {
                employee.dateIn_dang_m = "01";
            }
            else if (employee_view.dateIn_dang_m.Length == 1)
            {
                employee.dateIn_dang_m = "0" + employee_view.dateIn_dang_m;
            }
            else if (Int32.Parse(employee_view.dateIn_dang_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng vào đảng nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_dang_m = employee_view.dateIn_dang_m;
            }

            if (string.IsNullOrEmpty(employee_view.dateIn_dang_y) || Int32.Parse(employee_view.dateIn_dang_y) < 1900)
            {
                employee.dateIn_dang_y = "1900";
            }
            else if (employee_view.dateIn_dang_y.Length > 4 || employee_view.dateIn_dang_y.Length < 4 || employee_view.dateIn_dang_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm vào đảng nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_dang_y = employee_view.dateIn_dang_y;
            }
            employee.dateIn_dang = DateTime.ParseExact((employee.dateIn_dang_d + "/" + employee.dateIn_dang_m + "/" + employee.dateIn_dang_y), "dd/MM/yyyy", null);

            

            employee.ranks = employee_view.ranks;
            employee.salary_coefficient = employee_view.salary_coefficient;
            employee.positions = employee_view.positions;
            if (string.IsNullOrEmpty(employee_view.marital_status))
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Xin chọn tình trạng hôn nhân";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.marital_status = employee_view.marital_status;
            }
            employee.religion = employee_view.religion;
            employee.serial_number_officer = employee_view.serial_number_officer;
            employee.serial_number_military = employee_view.serial_number_military;
            employee.identity_card = employee_view.identity_card;
            ////Ngày cấp CMTND
            if (string.IsNullOrEmpty(employee_view.issuing_date_d) || employee_view.issuing_date_d == "0")
            {
                employee.issuing_date_d = "01";
            }
            else if (employee_view.issuing_date_d.Length == 1)
            {
                employee.issuing_date_d = "0" + employee_view.issuing_date_d;
            }
            else if (Int32.Parse(employee_view.issuing_date_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày cấp CMTND nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.issuing_date_d = employee_view.issuing_date_d;
            }
            if (string.IsNullOrEmpty(employee_view.issuing_date_m) || employee_view.issuing_date_m == "0")
            {
                employee.issuing_date_m = "01";
            }
            else if (employee_view.issuing_date_m.Length == 1)
            {
                employee.issuing_date_m = "0" + employee_view.issuing_date_m;
            }
            else if (Int32.Parse(employee_view.issuing_date_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng cấp CMTND nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.issuing_date_m = employee_view.issuing_date_m;
            }

            if (string.IsNullOrEmpty(employee_view.issuing_date_y) || Int32.Parse(employee_view.issuing_date_y) < 1900)
            {
                employee.issuing_date_y = "1900";
            }
            else if (employee_view.issuing_date_y.Length > 4 || employee_view.issuing_date_y.Length < 4 || employee_view.issuing_date_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm cấp CMTND nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.issuing_date_y = employee_view.issuing_date_y;
            }
            employee.issuing_date = DateTime.ParseExact((employee.issuing_date_d + "/" + employee.issuing_date_m + "/" + employee.issuing_date_y), "dd/MM/yyyy", null);
            //employee.issuing_date = employee_view.issuing_date;


            employee.place_of_issue = employee_view.place_of_issue;
            employee.army_identity_card = employee_view.army_identity_card;

            ////Ngày cấp CMTQĐ
            if (string.IsNullOrEmpty(employee_view.army_issuing_date_d) || employee_view.army_issuing_date_d == "0")
            {
                employee.army_issuing_date_d = "01";
            }
            else if (employee_view.army_issuing_date_d.Length == 1)
            {
                employee.army_issuing_date_d = "0" + employee_view.army_issuing_date_d;
            }
            else if (Int32.Parse(employee_view.army_issuing_date_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày cấp CMTQĐ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_issuing_date_d = employee_view.army_issuing_date_d;
            }
            if (string.IsNullOrEmpty(employee_view.army_issuing_date_m) || employee_view.army_issuing_date_m == "0")
            {
                employee.army_issuing_date_m = "01";
            }
            else if (employee_view.army_issuing_date_m.Length == 1)
            {
                employee.army_issuing_date_m = "0" + employee_view.army_issuing_date_m;
            }
            else if (Int32.Parse(employee_view.army_issuing_date_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng CMTQĐ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_issuing_date_m = employee_view.army_issuing_date_m;
            }

            if (string.IsNullOrEmpty(employee_view.army_issuing_date_y) || Int32.Parse(employee_view.army_issuing_date_y) < 1900)
            {
                employee.army_issuing_date_y = "1900";
            }
            else if (employee_view.army_issuing_date_y.Length > 4 || employee_view.army_issuing_date_y.Length < 4 || employee_view.army_issuing_date_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm CMTQĐ nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_issuing_date_y = employee_view.army_issuing_date_y;
            }
            employee.army_issuing_date = DateTime.ParseExact((employee.army_issuing_date_d + "/" + employee.army_issuing_date_m + "/" + employee.army_issuing_date_y), "dd/MM/yyyy", null);

            //employee.army_issuing_date = employee_view.army_issuing_date;

            employee.army_place_of_issue = employee_view.army_place_of_issue;
            employee.cultural_level = employee_view.cultural_level;
            employee.alias = employee_view.alias;
            employee.mobile = employee_view.mobile;
            employee.bank_account = employee_view.bank_account;
            employee.bank_name = employee_view.bank_name;
            employee.tax_code = employee_view.tax_code;
            employee.house_land_status = employee_view.house_land_status;
            employee.ethnic = employee_view.ethnic;

            //employee.army_join = employee_view.army_join;
            ////Ngày nhập ngũ
            if (string.IsNullOrEmpty(employee_view.army_join_d) || employee_view.army_join_d == "0")
            {
                employee.army_join_d = "01";
            }
            else if (employee_view.army_join_d.Length == 1)
            {
                employee.army_join_d = "0" + employee_view.army_join_d;
            }
            else if (Int32.Parse(employee_view.army_join_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày nhập ngũ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_join_d = employee_view.army_join_d;
            }
            if (string.IsNullOrEmpty(employee_view.army_join_m) || employee_view.army_join_m == "0")
            {
                employee.army_join_m = "01";
            }
            else if (employee_view.army_join_m.Length == 1)
            {
                employee.army_join_m = "0" + employee_view.army_join_m;
            }
            else if (Int32.Parse(employee_view.army_join_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng nhập ngũ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_join_m = employee_view.army_join_m;
            }

            if (string.IsNullOrEmpty(employee_view.army_join_y) || Int32.Parse(employee_view.army_join_y) < 1900)
            {
                employee.army_join_y = "1900";
            }
            else if (employee_view.army_join_y.Length > 4 || employee_view.army_join_y.Length < 4 || employee_view.army_join_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm nhập ngũ nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_join_y = employee_view.army_join_y;
            }
            employee.army_join = DateTime.ParseExact((employee.army_join_d + "/" + employee.army_join_m + "/" + employee.army_join_y), "dd/MM/yyyy", null);

            if (employee_view.employee_status==null)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Xin chọn trạng thái";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.employee_status = employee_view.employee_status;
            }
            
            employee.foreign_language = employee_view.foreign_language;
            //employee.object_employee_id = employee_view.object_employee_id; //Đưa danh sách đối tượng nhân viên cha con ra
            //employee.departments_id = employee_view.departments_id;          //Đưa ra dropdownlist danh sách phòng ban
            employee.object_employee_id = employee_view.object_employee_id;
            employee.avarta = employee_view.avarta;
            employee.description_detail = employee_view.description_detail;

            //employee.date_join = employee_view.date_join;
            ////Ngày vào công ty
            if (string.IsNullOrEmpty(employee_view.date_join_d) || employee_view.date_join_d == "0")
            {
                employee.date_join_d = "01";
            }
            else if (employee_view.date_join_d.Length == 1)
            {
                employee.date_join_d = "0" + employee_view.date_join_d;
            }
            else if (Int32.Parse(employee_view.date_join_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày vào công ty nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.date_join_d = employee_view.date_join_d;
            }
            if (string.IsNullOrEmpty(employee_view.date_join_m) || employee_view.date_join_m == "0")
            {
                employee.date_join_m = "01";
            }
            else if (employee_view.date_join_m.Length == 1)
            {
                employee.date_join_m = "0" + employee_view.date_join_m;
            }
            else if (Int32.Parse(employee_view.date_join_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng vào công ty nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.date_join_m = employee_view.date_join_m;
            }

            if (string.IsNullOrEmpty(employee_view.date_join_y) || Int32.Parse(employee_view.date_join_y) < 1900)
            {
                employee.date_join_y = "1900";
            }
            else if (employee_view.date_join_y.Length > 4 || employee_view.date_join_y.Length < 4 || employee_view.date_join_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm vào công ty nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.date_join_y = employee_view.date_join_y;
            }
            employee.date_join = DateTime.ParseExact((employee.date_join_d + "/" + employee.date_join_m + "/" + employee.date_join_y), "dd/MM/yyyy", null);


            //employee.unit = employee_view.unit;
            employee.created_date = DateTime.Now;
            employee.created_by = int.Parse(Session["user_id"].ToString());


            int new_id = h_contentModels.createEmployee(employee);

            if (new_id > 0)
            {
                //add group for user
                //if (!string.IsNullOrEmpty(employee_view.arr_departments_id))
                //{
                //    var arr = employee_view.arr_departments_id.Split(',');
                //    foreach (var item in arr)
                //    {
                //        if (!string.IsNullOrEmpty(item))
                //        {
                //            h_contentModels.addDepartmentEmployee(int.Parse(item.ToString()), new_id);
                //        }
                //    }
                //}
                if (employee_view.departments_id != null)
                {
                    //delete all group of user
                    //h_contentModels.deleteDepartmentEmployee(employee.employee_id);
                    //add new list group for user
                    h_contentModels.addDepartmentEmployee((int)employee_view.departments_id, new_id);
                }
                ViewBag.result_message = "Tạo hồ sơ mới thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/"+new_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tạo hồ sơ mới lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
        }
        //Cập nhật hồ sơ
        public ActionResult edit_employee()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee(int? id)
        {
            ViewBag.isAdd = false;
            var employee_view = new ViewModels.EmployeeViewModels();
            //employee_view.list_department = h_contentModels.getListDepartment();
            employee_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            employee_view.list_obj_employee = h_contentModels.getListobject_employeeBuilder(null);


            var employee = h_contentModels.getEmployeeByID(id ?? 0);
            if (employee != null)
            {
                employee_view.employee_id = employee.employee_id;
                employee_view.employee_code = employee.employee_code;
                employee_view.full_name = employee.full_name;
                employee_view.b_day = employee.b_day;
                employee_view.b_month = employee.b_month;
                employee_view.b_year = employee.b_year;
                employee_view.phone = employee.phone;
                employee_view.email = employee.email;
                employee_view.gender = employee.gender;
                employee_view.family_reduction = employee.family_reduction;
                employee_view.hometown = employee.hometown;
                employee_view.current_address = employee.current_address;
                employee_view.household_registration = employee.household_registration;
                employee_view.dateIn_doan_d = employee.dateIn_doan_d;
                employee_view.dateIn_doan_m = employee.dateIn_doan_m;
                employee_view.dateIn_doan_y = employee.dateIn_doan_y;

                employee_view.dateIn_dang_d = employee.dateIn_dang_d;
                employee_view.dateIn_dang_m = employee.dateIn_dang_m;
                employee_view.dateIn_dang_y = employee.dateIn_dang_y;
                
                employee_view.ranks = employee.ranks;
                employee_view.salary_coefficient = employee.salary_coefficient;
                employee_view.positions = employee.positions;
                employee_view.marital_status = employee.marital_status;
                employee_view.religion = employee.religion;
                employee_view.serial_number_officer = employee.serial_number_officer;
                employee_view.serial_number_military = employee.serial_number_military;
                employee_view.identity_card = employee.identity_card;
                //employee_view.issuing_date = employee.issuing_date;
                employee_view.issuing_date_d = employee.issuing_date_d;
                employee_view.issuing_date_m = employee.issuing_date_m;
                employee_view.issuing_date_y = employee.issuing_date_y;

                employee_view.place_of_issue = employee.place_of_issue;
                employee_view.army_identity_card = employee.army_identity_card;
                //employee_view.army_issuing_date = employee.army_issuing_date;
                employee_view.army_issuing_date_d = employee.army_issuing_date_d;
                employee_view.army_issuing_date_m = employee.army_issuing_date_m;
                employee_view.army_issuing_date_y = employee.army_issuing_date_y;

                employee_view.army_place_of_issue = employee.army_place_of_issue;
                employee_view.cultural_level = employee.cultural_level;
                employee_view.alias = employee.alias;
                employee_view.mobile = employee.mobile;
                employee_view.bank_account = employee.bank_account;
                employee_view.bank_name = employee.bank_name;
                employee_view.tax_code = employee.tax_code;
                employee_view.house_land_status = employee.house_land_status;
                employee_view.ethnic = employee.ethnic;
                //employee_view.army_join = employee.army_join;
                employee_view.army_join_d = employee.army_join_d;
                employee_view.army_join_m = employee.army_join_m;
                employee_view.army_join_y = employee.army_join_y;

                employee_view.employee_status = employee.employee_status;
                employee_view.foreign_language = employee.foreign_language;
                employee_view.object_employee_id = employee.object_employee_id;  //Đưa ra dropdownlist đối tượng nhân viên
                //employee_view.arr_departments_id = h_contentModels.getListDepartmentEmployee(id ?? 0).ToArray().ToString();      //Đưa ra dropdownlist danh sách phòng ban
                var list_arr = h_contentModels.getListDepartmentEmployee(id ?? 0).ToList();
                for (int i = 0; i < list_arr.Count(); i++)
                {
                    employee_view.arr_departments_id = employee_view.arr_departments_id + list_arr[i].ToString() + ",";
                }
                if (!string.IsNullOrEmpty(employee_view.arr_departments_id))
                {
                    if (employee_view.arr_departments_id.EndsWith(","))
                    {
                        employee_view.arr_departments_id = employee_view.arr_departments_id.Substring(0, employee_view.arr_departments_id.LastIndexOf(","));
                    }
                }
                
                employee_view.avarta = employee.avarta;
                employee_view.created_date = employee.created_date;
                employee_view.created_by = employee.created_by;
                employee_view.description_detail = employee.description_detail;
                //employee_view.date_join = employee.date_join;
                employee_view.date_join_d = employee.date_join_d;
                employee_view.date_join_m = employee.date_join_m;
                employee_view.date_join_y = employee.date_join_y;
               // employee_view.unit = employee.unit;
            }


            return PartialView("../Shared/control_detail_employee", employee_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee(FormCollection collection)
        {
            var employee_view = new ViewModels.EmployeeViewModels();
            TryUpdateModel(employee_view);
            employee_view.list_obj_employee = h_contentModels.getListobject_employeeBuilder(null);
            employee_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            var employee = h_contentModels.getEmployeeByID(employee_view.employee_id ?? 0);
            employee.employee_id = (int)employee_view.employee_id;
            employee.employee_code = employee_view.employee_code;
            employee.full_name = employee_view.full_name;
            //employee.birth_day = employee_view.birth_day;
            //if (employee.birth_day != null)
            //{
            //    employee.b_day = employee_view.birth_day.Value.Day;
            //    employee.b_month = employee_view.birth_day.Value.Month;
            //    employee.b_year = employee_view.birth_day.Value.Year;
            //}
            if (employee_view.b_day == null)
            {
                employee.b_day = 01;
            }
            else if (employee_view.b_day > 31 || employee_view.b_day == 0)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày sinh nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.b_day = employee_view.b_day;
            }
            //thangs sinh
            if (employee_view.b_month == null)
            {
                employee.b_month = 01;
            }
            else if (employee_view.b_month == 0 || employee_view.b_month > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng sinh nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.b_month = employee_view.b_month;
            }

            //năm sinh
            if (employee_view.b_year == null || employee_view.b_year < 1900)
            {
                employee.b_year = 1900;
            }
            else
            {
                employee.b_year = employee_view.b_year;
            }
            employee.birth_day = DateTime.ParseExact(string.Format("{0:00}", employee.b_day) + "/" + string.Format("{0:00}", employee.b_month) + "/" + employee.b_year, "dd/MM/yyyy", null);
            employee.phone = employee_view.phone;
            employee.email = employee_view.email;
            employee.gender = employee_view.gender;
            employee.family_reduction = employee_view.family_reduction;
            employee.hometown = employee_view.hometown;
            employee.current_address = employee_view.current_address;
            employee.household_registration = employee_view.household_registration;
            //employee.dateIn_doan = employee_view.dateIn_doan;
            //Ngày vào đoàn
            if (string.IsNullOrEmpty(employee_view.dateIn_doan_d) || employee_view.dateIn_doan_d == "0")
            {
                employee.dateIn_doan_d = "01";
            }
            else if (employee_view.dateIn_doan_d.Length == 1)
            {
                employee.dateIn_doan_d = "0" + employee_view.dateIn_doan_d;
            }
            else if (Int32.Parse(employee_view.dateIn_doan_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày vào đoàn nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_doan_d = employee_view.dateIn_doan_d;
            }
            if (string.IsNullOrEmpty(employee_view.dateIn_doan_m) || employee_view.dateIn_doan_m == "0")
            {
                employee.dateIn_doan_m = "01";
            }
            else if (employee_view.dateIn_doan_m.Length == 1)
            {
                employee.dateIn_doan_m = "0" + employee_view.dateIn_doan_m;
            }
            else if (Int32.Parse(employee_view.dateIn_doan_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng vào đoàn  nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_doan_m = employee_view.dateIn_doan_m;
            }

            if (string.IsNullOrEmpty(employee_view.dateIn_doan_y) || Int32.Parse(employee_view.dateIn_doan_y) < 1900)
            {
                employee.dateIn_doan_y = "1900";
            }
            else if (employee_view.dateIn_doan_y.Length > 4 || employee_view.dateIn_doan_y.Length < 4 || employee_view.dateIn_doan_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng vào đoàn nhập chưa đúng";
                ViewBag.result_message = "Năm nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_doan_y = employee_view.dateIn_doan_y;
            }
            employee.dateIn_doan = DateTime.ParseExact((employee.dateIn_doan_d + "/" + employee.dateIn_doan_m + "/" + employee.dateIn_doan_y), "dd/MM/yyyy", null);

            //employee.dateIn_dang = employee_view.dateIn_dang;
            ////Ngày vào đảng
            if (string.IsNullOrEmpty(employee_view.dateIn_dang_d) || employee_view.dateIn_dang_d == "0")
            {
                employee.dateIn_dang_d = "01";
            }
            else if (employee_view.dateIn_dang_d.Length == 1)
            {
                employee.dateIn_dang_d = "0" + employee_view.dateIn_dang_d;
            }
            else if (Int32.Parse(employee_view.dateIn_dang_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày vào đảng nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_dang_d = employee_view.dateIn_dang_d;
            }
            if (string.IsNullOrEmpty(employee_view.dateIn_dang_m) || employee_view.dateIn_dang_m == "0")
            {
                employee.dateIn_dang_m = "01";
            }
            else if (employee_view.dateIn_dang_m.Length == 1)
            {
                employee.dateIn_dang_m = "0" + employee_view.dateIn_dang_m;
            }
            else if (Int32.Parse(employee_view.dateIn_dang_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng vào đảng nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_dang_m = employee_view.dateIn_dang_m;
            }

            if (string.IsNullOrEmpty(employee_view.dateIn_dang_y) || Int32.Parse(employee_view.dateIn_dang_y) < 1900)
            {
                employee.dateIn_dang_y = "1900";
            }
            else if (employee_view.dateIn_dang_y.Length > 4 || employee_view.dateIn_dang_y.Length < 4 || employee_view.dateIn_dang_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm vào đảng nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.dateIn_dang_y = employee_view.dateIn_dang_y;
            }
            employee.dateIn_dang = DateTime.ParseExact((employee.dateIn_dang_d + "/" + employee.dateIn_dang_m + "/" + employee.dateIn_dang_y), "dd/MM/yyyy", null);


            employee.ranks = employee_view.ranks;
            employee.salary_coefficient = employee_view.salary_coefficient;
            employee.positions = employee_view.positions;

            if (employee.marital_status == "2" || employee.marital_status ==null)
            {
                ViewBag.result_message = "Xin chọn tình trạng hôn nhân";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.marital_status = employee_view.marital_status;
            }
            employee.religion = employee_view.religion;
            employee.serial_number_officer = employee_view.serial_number_officer;
            employee.serial_number_military = employee_view.serial_number_military;
            employee.identity_card = employee_view.identity_card;
            //employee.issuing_date = employee_view.issuing_date;
            ////Ngày cấp CMTND
            if (string.IsNullOrEmpty(employee_view.issuing_date_d) || employee_view.issuing_date_d == "0")
            {
                employee.issuing_date_d = "01";
            }
            else if (employee_view.issuing_date_d.Length == 1)
            {
                employee.issuing_date_d = "0" + employee_view.issuing_date_d;
            }
            else if (Int32.Parse(employee_view.issuing_date_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày cấp CMTND nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.issuing_date_d = employee_view.issuing_date_d;
            }
            if (string.IsNullOrEmpty(employee_view.issuing_date_m) || employee_view.issuing_date_m == "0")
            {
                employee.issuing_date_m = "01";
            }
            else if (employee_view.issuing_date_m.Length == 1)
            {
                employee.issuing_date_m = "0" + employee_view.issuing_date_m;
            }
            else if (Int32.Parse(employee_view.issuing_date_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng cấp CMTND nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.issuing_date_m = employee_view.issuing_date_m;
            }

            if (string.IsNullOrEmpty(employee_view.issuing_date_y) || Int32.Parse(employee_view.issuing_date_y) < 1900)
            {
                employee.issuing_date_y = "1900";
            }
            else if (employee_view.issuing_date_y.Length > 4 || employee_view.issuing_date_y.Length < 4 || employee_view.issuing_date_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm cấp CMTND nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.issuing_date_y = employee_view.issuing_date_y;
            }
            employee.issuing_date = DateTime.ParseExact((employee.issuing_date_d + "/" + employee.issuing_date_m + "/" + employee.issuing_date_y), "dd/MM/yyyy", null);
           
            employee.place_of_issue = employee_view.place_of_issue;
            employee.army_identity_card = employee_view.army_identity_card;
            //employee.army_issuing_date = employee_view.army_issuing_date;
            ////Ngày cấp CMTQĐ
            if (string.IsNullOrEmpty(employee_view.army_issuing_date_d) || employee_view.army_issuing_date_d == "0")
            {
                employee.army_issuing_date_d = "01";
            }
            else if (employee_view.army_issuing_date_d.Length == 1)
            {
                employee.army_issuing_date_d = "0" + employee_view.army_issuing_date_d;
            }
            else if (Int32.Parse(employee_view.army_issuing_date_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày cấp CMTQĐ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_issuing_date_d = employee_view.army_issuing_date_d;
            }
            if (string.IsNullOrEmpty(employee_view.army_issuing_date_m) || employee_view.army_issuing_date_m == "0")
            {
                employee.army_issuing_date_m = "01";
            }
            else if (employee_view.army_issuing_date_m.Length == 1)
            {
                employee.army_issuing_date_m = "0" + employee_view.army_issuing_date_m;
            }
            else if (Int32.Parse(employee_view.army_issuing_date_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng CMTQĐ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_issuing_date_m = employee_view.army_issuing_date_m;
            }

            if (string.IsNullOrEmpty(employee_view.army_issuing_date_y) || Int32.Parse(employee_view.army_issuing_date_y) < 1900)
            {
                employee.army_issuing_date_y = "1900";
            }
            else if (employee_view.army_issuing_date_y.Length > 4 || employee_view.army_issuing_date_y.Length < 4 || employee_view.army_issuing_date_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm CMTQĐ nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_issuing_date_y = employee_view.army_issuing_date_y;
            }
            employee.army_issuing_date = DateTime.ParseExact((employee.army_issuing_date_d + "/" + employee.army_issuing_date_m + "/" + employee.army_issuing_date_y), "dd/MM/yyyy", null);

            employee.army_place_of_issue = employee_view.army_place_of_issue;
            employee.cultural_level = employee_view.cultural_level;
            employee.alias = employee_view.alias;
            employee.mobile = employee_view.mobile;
            employee.bank_account = employee_view.bank_account;
            employee.bank_name = employee_view.bank_name;
            employee.tax_code = employee_view.tax_code;
            employee.house_land_status = employee_view.house_land_status;
            employee.ethnic = employee_view.ethnic;
            //employee.army_join = employee_view.army_join;
            ////Ngày nhập ngũ
            if (string.IsNullOrEmpty(employee_view.army_join_d) || employee_view.army_join_d == "0")
            {
                employee.army_join_d = "01";
            }
            else if (employee_view.army_join_d.Length == 1)
            {
                employee.army_join_d = "0" + employee_view.army_join_d;
            }
            else if (Int32.Parse(employee_view.army_join_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày nhập ngũ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_join_d = employee_view.army_join_d;
            }
            if (string.IsNullOrEmpty(employee_view.army_join_m) || employee_view.army_join_m == "0")
            {
                employee.army_join_m = "01";
            }
            else if (employee_view.army_join_m.Length == 1)
            {
                employee.army_join_m = "0" + employee_view.army_join_m;
            }
            else if (Int32.Parse(employee_view.army_join_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng nhập ngũ nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_join_m = employee_view.army_join_m;
            }

            if (string.IsNullOrEmpty(employee_view.army_join_y) || Int32.Parse(employee_view.army_join_y) < 1900)
            {
                employee.army_join_y = "1900";
            }
            else if (employee_view.army_join_y.Length > 4 || employee_view.army_join_y.Length < 4 || employee_view.army_join_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm nhập ngũ nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.army_join_y = employee_view.army_join_y;
            }
            employee.army_join = DateTime.ParseExact((employee.army_join_d + "/" + employee.army_join_m + "/" + employee.army_join_y), "dd/MM/yyyy", null);


            employee.employee_status = employee_view.employee_status;
            employee.foreign_language = employee_view.foreign_language;
            employee.object_employee_id = employee_view.object_employee_id;  //Đưa ra dropdownlist đối tượng nhân viên
            //employee.departments_id = employee_view.departments_id;          //Đưa ra dropdownlist danh sách phòng ban
            employee.avarta = employee_view.avarta;
            employee.description_detail = employee_view.description_detail;
            //employee.date_join = employee_view.date_join;
            ////Ngày vào công ty
            if (string.IsNullOrEmpty(employee_view.date_join_d) || employee_view.date_join_d == "0")
            {
                employee.date_join_d = "01";
            }
            else if (employee_view.date_join_d.Length == 1)
            {
                employee.date_join_d = "0" + employee_view.date_join_d;
            }
            else if (Int32.Parse(employee_view.date_join_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày vào công ty nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.date_join_d = employee_view.date_join_d;
            }
            if (string.IsNullOrEmpty(employee_view.date_join_m) || employee_view.date_join_m == "0")
            {
                employee.date_join_m = "01";
            }
            else if (employee_view.date_join_m.Length == 1)
            {
                employee.date_join_m = "0" + employee_view.date_join_m;
            }
            else if (Int32.Parse(employee_view.date_join_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng vào công ty nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.date_join_m = employee_view.date_join_m;
            }

            if (string.IsNullOrEmpty(employee_view.date_join_y) || Int32.Parse(employee_view.date_join_y) < 1900)
            {
                employee.date_join_y = "1900";
            }
            else if (employee_view.date_join_y.Length > 4 || employee_view.date_join_y.Length < 4 || employee_view.date_join_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm vào công ty nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee", employee_view);
            }
            else
            {
                employee.date_join_y = employee_view.date_join_y;
            }
            employee.date_join = DateTime.ParseExact((employee.date_join_d + "/" + employee.date_join_m + "/" + employee.date_join_y), "dd/MM/yyyy", null);

            //employee.unit = employee_view.unit;
            employee.modified_date = DateTime.Now;
            employee.modified_by = int.Parse(Session["user_id"].ToString());


            h_contentModels.editEmployee(employee);
            //if (!string.IsNullOrEmpty(employee_view.arr_departments_id))
            //{
            //    var arr = employee_view.arr_departments_id.Split(',');
            //    var arrs = arr.ToList();
            //    if (arrs.Count > 0)
            //    {

            //        if (arrs[0] != "System.Int32[]")
            //        {
            //            for (int i = 0; i < arr.Length; i++)
            //            {
            //                //delete all group of user
            //                h_contentModels.deleteDepartmentEmployee(employee.employee_id);
            //                //add new list group for user
            //                if (!string.IsNullOrEmpty(arrs[i]))
            //                {
            //                    h_contentModels.addDepartmentEmployee(int.Parse(arrs[i]), employee.employee_id);
            //                }
            //            }
            //        }

            //    }
            //}
            if (employee_view.departments_id != null)
            {
                //delete all group of user
                h_contentModels.deleteDepartmentEmployee(employee.employee_id);
                //add new list group for user
                h_contentModels.addDepartmentEmployee((int)employee_view.departments_id, employee.employee_id);
            }
            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/" + employee.employee_id;
            return PartialView("../Shared/control_redirect");
        }



        //Thêm hợp đồng
        public ActionResult add_employee_contract()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_contract(int? id)
        {
            ViewBag.isAdd = true;
            var contract_view = new ViewModels.EmployeeContractViewModels();
            contract_view.employee_id = id;
            contract_view.listTypeContract = h_contentModels.getListTypeContract();
            return PartialView("../Shared/control_detail_employee_contract", contract_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_contract(FormCollection collection)
        {
            var contract_view = new ViewModels.EmployeeContractViewModels();
            TryUpdateModel(contract_view);
            contract_view.listTypeContract = h_contentModels.getListTypeContract();
            web.data.entities.contract contract = new data.entities.contract();
            contract.employee_id = contract_view.employee_id;
            if (contract_view.type_contract_id != null)
            {
                contract.type_contract_id = contract_view.type_contract_id;
            }
            else {
                ViewBag.result_message = "Xin chọn loại hợp đồng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            if (string.IsNullOrEmpty(contract_view.contract_name))
            {
                ViewBag.result_message = "Nhập tên hợp đồng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.contract_name = contract_view.contract_name;
            }
            //contract.enable_start = contract_view.enable_start;
            if (string.IsNullOrEmpty(contract_view.enable_start_d) || contract_view.enable_start_d == "0")
            {
                contract.enable_start_d = "01";
            }
            else if (contract_view.enable_start_d.Length == 1)
            {
                contract.enable_start_d = "0" + contract_view.enable_start_d;
            }
            else if (Int32.Parse(contract_view.enable_start_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày có hiệu lực nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.enable_start_d = contract_view.enable_start_d;
            }
            if (string.IsNullOrEmpty(contract_view.enable_start_m) || contract_view.enable_start_m == "0")
            {
                contract.enable_start_m = "01";
            }
            else if (contract_view.enable_start_m.Length == 1)
            {
                contract.enable_start_m = "0" + contract_view.enable_start_m;
            }
            else if (Int32.Parse(contract_view.enable_start_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng có hiệu lực nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.enable_start_m = contract_view.enable_start_m;
            }

            if (string.IsNullOrEmpty(contract_view.enable_start_y) || Int32.Parse(contract_view.enable_start_y) < 1900)
            {
                contract.enable_start_y = "1900";
            }
            else if (contract_view.enable_start_y.Length > 4 || contract_view.enable_start_y.Length < 4 || contract_view.enable_start_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm có hiệu lực  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.enable_start_y = contract_view.enable_start_y;
            }
            contract.enable_start = DateTime.ParseExact((contract.enable_start_d + "/" + contract.enable_start_m + "/" + contract.enable_start_y), "dd/MM/yyyy", null);

            //contract.enable_end = contract_view.enable_end;
            if (string.IsNullOrEmpty(contract_view.enable_end_d) || contract_view.enable_end_d == "0")
            {
                contract.enable_end_d = "01";
            }
            else if (contract_view.enable_end_d.Length == 1)
            {
                contract.enable_end_d = "0" + contract_view.enable_end_d;
            }
            else if (Int32.Parse(contract_view.enable_end_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày có hiệu lực nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.enable_end_d = contract_view.enable_end_d;
            }
            if (string.IsNullOrEmpty(contract_view.enable_end_m) || contract_view.enable_end_m == "0")
            {
                contract.enable_end_m = "01";
            }
            else if (contract_view.enable_end_m.Length == 1)
            {
                contract.enable_end_m = "0" + contract_view.enable_end_m;
            }
            else if (Int32.Parse(contract_view.enable_end_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng có hiệu lực nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.enable_end_m = contract_view.enable_end_m;
            }

            if (string.IsNullOrEmpty(contract_view.enable_end_y) || Int32.Parse(contract_view.enable_end_y) < 1900)
            {
                contract.enable_end_y = "1900";
            }
            else if (contract_view.enable_end_y.Length > 4 || contract_view.enable_end_y.Length < 4 || contract_view.enable_end_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm có hiệu lực  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.enable_end_y = contract_view.enable_end_y;
            }
            contract.enable_end = DateTime.ParseExact((contract.enable_end_d + "/" + contract.enable_end_m + "/" + contract.enable_end_y), "dd/MM/yyyy", null);


            //contract.signature_date = contract_view.signature_date;
            if (string.IsNullOrEmpty(contract_view.signature_date_d) || contract_view.signature_date_d == "0")
            {
                contract.signature_date_d = "01";
            }
            else if (contract_view.signature_date_d.Length == 1)
            {
                contract.signature_date_d = "0" + contract_view.signature_date_d;
            }
            else if (Int32.Parse(contract_view.signature_date_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày có hiệu lực nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.signature_date_d = contract_view.signature_date_d;
            }
            if (string.IsNullOrEmpty(contract_view.signature_date_m) || contract_view.signature_date_m == "0")
            {
                contract.signature_date_m = "01";
            }
            else if (contract_view.signature_date_m.Length == 1)
            {
                contract.signature_date_m = "0" + contract_view.signature_date_m;
            }
            else if (Int32.Parse(contract_view.signature_date_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng có hiệu lực nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.signature_date_m = contract_view.signature_date_m;
            }

            if (string.IsNullOrEmpty(contract_view.signature_date_y) || Int32.Parse(contract_view.signature_date_y) < 1900)
            {
                contract.signature_date_y = "1900";
            }
            else if (contract_view.signature_date_y.Length > 4 || contract_view.signature_date_y.Length < 4 || contract_view.signature_date_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm có hiệu lực  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else
            {
                contract.signature_date_y = contract_view.signature_date_y;
            }
            contract.signature_date = DateTime.ParseExact((contract.signature_date_d + "/" + contract.signature_date_m + "/" + contract.signature_date_y), "dd/MM/yyyy", null);


            contract.signature_name = contract_view.signature_name;
            contract.positions = contract_view.positions;
            contract.files = contract_view.files;
            contract.contract_status = contract_view.contract_status;

            int new_id = h_contentModels.createContract(contract);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo hồ sơ mới thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + contract.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo hồ sơ mới lỗi lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
        }

        //Sửa hợp đồng
        public ActionResult edit_employee_contract()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_contract(int? id)
        {
            ViewBag.isAdd = false;
            var contract_view = new ViewModels.EmployeeContractViewModels();
            contract_view.listTypeContract = h_contentModels.getListTypeContract();
            var contract = h_contentModels.getContractByID(id ?? 0);
            if (contract != null)
            {
                contract_view.contract_id = contract.contract_id;
                contract_view.contract_name = contract.contract_name;
                //contract_view.enable_end = contract.enable_start;
                contract_view.enable_start_d = contract.enable_start_d;
                contract_view.enable_start_m = contract.enable_start_m;
                contract_view.enable_start_y = contract.enable_start_y;

                //contract_view.enable_end = contract.enable_end;
                contract_view.enable_end_d = contract.enable_end_d;
                contract_view.enable_end_m = contract.enable_end_m;
                contract_view.enable_end_y = contract.enable_end_y;

                contract_view.contract_status = contract.contract_status;
                contract_view.files = contract.files;
                contract_view.signature_name = contract.signature_name;
                //contract_view.signature_date = contract.signature_date;
                contract_view.signature_date_d = contract.signature_date_d;
                contract_view.signature_date_m = contract.signature_date_m;
                contract_view.signature_date_y = contract.signature_date_y;
                contract_view.positions = contract.positions;
                contract_view.type_contract_id = contract.type_contract_id;
                contract_view.employee_id = contract.employee_id;
            }


            return PartialView("../Shared/control_detail_employee_contract", contract_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_contract(FormCollection collection)
        {
            var contract_view = new ViewModels.EmployeeContractViewModels();
            TryUpdateModel(contract_view);
            contract_view.listTypeContract = h_contentModels.getListTypeContract();
            var contract = h_contentModels.getContractByID(contract_view.contract_id ?? 0);
            if (string.IsNullOrEmpty(contract_view.contract_name))
            {
                ViewBag.result_message = "Nhập tên hợp đồng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_contract", contract_view);
            }
            else {
                contract.contract_name = contract_view.contract_name;
            }

            

                contract.contract_id = (int)contract_view.contract_id;
                if (contract_view.type_contract_id != null)
                {
                    contract.type_contract_id = contract_view.type_contract_id;
                }
                else
                {
                    ViewBag.result_message = "Xin chọn loại hợp đồng.";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                contract.contract_status = contract_view.contract_status;
                contract.files = contract_view.files;
                contract.signature_name = contract_view.signature_name;
                contract.positions = contract_view.positions;
                contract.type_contract_id = contract_view.type_contract_id;
                contract.employee_id = contract_view.employee_id;
                //contract.enable_start = contract_view.enable_start;
                if (string.IsNullOrEmpty(contract_view.enable_start_d) || contract_view.enable_start_d == "0")
                {
                    contract.enable_start_d = "01";
                }
                else if (contract_view.enable_start_d.Length == 1)
                {
                    contract.enable_start_d = "0" + contract_view.enable_start_d;
                }
                else if (Int32.Parse(contract_view.enable_start_d) > 31)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Ngày có hiệu lực nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.enable_start_d = contract_view.enable_start_d;
                }
                if (string.IsNullOrEmpty(contract_view.enable_start_m) || contract_view.enable_start_m == "0")
                {
                    contract.enable_start_m = "01";
                }
                else if (contract_view.enable_start_m.Length == 1)
                {
                    contract.enable_start_m = "0" + contract_view.enable_start_m;
                }
                else if (Int32.Parse(contract_view.enable_start_m) > 12)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Tháng có hiệu lực nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.enable_start_m = contract_view.enable_start_m;
                }

                if (string.IsNullOrEmpty(contract_view.enable_start_y) || Int32.Parse(contract_view.enable_start_y) < 1900)
                {
                    contract.enable_start_y = "1900";
                }
                else if (contract_view.enable_start_y.Length > 4 || contract_view.enable_start_y.Length < 4 || contract_view.enable_start_y == "0000")
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Năm có hiệu lực  nhập chưa chính xác";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.enable_start_y = contract_view.enable_start_y;
                }
                contract.enable_start = DateTime.ParseExact((contract.enable_start_d + "/" + contract.enable_start_m + "/" + contract.enable_start_y), "dd/MM/yyyy", null);

                //contract.enable_end = contract_view.enable_end;
                if (string.IsNullOrEmpty(contract_view.enable_end_d) || contract_view.enable_end_d == "0")
                {
                    contract.enable_end_d = "01";
                }
                else if (contract_view.enable_end_d.Length == 1)
                {
                    contract.enable_end_d = "0" + contract_view.enable_end_d;
                }
                else if (Int32.Parse(contract_view.enable_end_d) > 31)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Ngày có hiệu lực nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.enable_end_d = contract_view.enable_end_d;
                }
                if (string.IsNullOrEmpty(contract_view.enable_end_m) || contract_view.enable_end_m == "0")
                {
                    contract.enable_end_m = "01";
                }
                else if (contract_view.enable_end_m.Length == 1)
                {
                    contract.enable_end_m = "0" + contract_view.enable_end_m;
                }
                else if (Int32.Parse(contract_view.enable_end_m) > 12)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Tháng có hiệu lực nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.enable_end_m = contract_view.enable_end_m;
                }

                if (string.IsNullOrEmpty(contract_view.enable_end_y) || Int32.Parse(contract_view.enable_end_y) < 1900)
                {
                    contract.enable_end_y = "1900";
                }
                else if (contract_view.enable_end_y.Length > 4 || contract_view.enable_end_y.Length < 4 || contract_view.enable_end_y == "0000")
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Năm có hiệu lực  nhập chưa chính xác";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.enable_end_y = contract_view.enable_end_y;
                }
                contract.enable_end = DateTime.ParseExact((contract.enable_end_d + "/" + contract.enable_end_m + "/" + contract.enable_end_y), "dd/MM/yyyy", null);


                //contract.signature_date = contract_view.signature_date;
                if (string.IsNullOrEmpty(contract_view.signature_date_d) || contract_view.signature_date_d == "0")
                {
                    contract.signature_date_d = "01";
                }
                else if (contract_view.signature_date_d.Length == 1)
                {
                    contract.signature_date_d = "0" + contract_view.signature_date_d;
                }
                else if (Int32.Parse(contract_view.signature_date_d) > 31)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Ngày có hiệu lực nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.signature_date_d = contract_view.signature_date_d;
                }
                if (string.IsNullOrEmpty(contract_view.signature_date_m) || contract_view.signature_date_m == "0")
                {
                    contract.signature_date_m = "01";
                }
                else if (contract_view.signature_date_m.Length == 1)
                {
                    contract.signature_date_m = "0" + contract_view.signature_date_m;
                }
                else if (Int32.Parse(contract_view.signature_date_m) > 12)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Tháng có hiệu lực nhập chưa đúng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.signature_date_m = contract_view.signature_date_m;
                }

                if (string.IsNullOrEmpty(contract_view.signature_date_y) || Int32.Parse(contract_view.signature_date_y) < 1900)
                {
                    contract.signature_date_y = "1900";
                }
                else if (contract_view.signature_date_y.Length > 4 || contract_view.signature_date_y.Length < 4 || contract_view.signature_date_y == "0000")
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Năm có hiệu lực  nhập chưa chính xác";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_employee_contract", contract_view);
                }
                else
                {
                    contract.signature_date_y = contract_view.signature_date_y;
                }
                contract.signature_date = DateTime.ParseExact((contract.signature_date_d + "/" + contract.signature_date_m + "/" + contract.signature_date_y), "dd/MM/yyyy", null);


            h_contentModels.edit_employee_contract(contract);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/"+contract.employee_id;
            return PartialView("../Shared/control_redirect");
        }
        //Thêm hồ sơ sức khỏe
        public ActionResult add_employee_medicalRecord()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_medicalRecord(int? id)
        {
            ViewBag.isAdd = true;
            var medicalRecord_view = new ViewModels.EmployeeMedicalRecordsViewModels();
            medicalRecord_view.employee_id = id;
            return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_medicalRecord(FormCollection collection)
        {
            var medicalRecord_view = new ViewModels.EmployeeMedicalRecordsViewModels();
            TryUpdateModel(medicalRecord_view);

            web.data.entities.employee_medical_records medicalRecord = new data.entities.employee_medical_records();
            medicalRecord.employee_id = medicalRecord_view.employee_id;
            //medicalRecord.date_medical_examination = medicalRecord_view.date_medical_examination;
            if (string.IsNullOrEmpty(medicalRecord_view.date_medical_examination_d) || medicalRecord_view.date_medical_examination_d == "0")
            {
                medicalRecord.date_medical_examination_d = "01";
            }
            else if (medicalRecord_view.date_medical_examination_d.Length == 1)
            {
                medicalRecord.date_medical_examination_d = "0" + medicalRecord_view.date_medical_examination_d;
            }
            else if (Int32.Parse(medicalRecord_view.date_medical_examination_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày khám nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
            }
            else
            {
                medicalRecord.date_medical_examination_d = medicalRecord_view.date_medical_examination_d;
            }
            if (string.IsNullOrEmpty(medicalRecord_view.date_medical_examination_m) || medicalRecord_view.date_medical_examination_m == "0")
            {
                medicalRecord.date_medical_examination_m = "01";
            }
            else if (medicalRecord_view.date_medical_examination_m.Length == 1)
            {
                medicalRecord.date_medical_examination_m = "0" + medicalRecord_view.date_medical_examination_m;
            }
            else if (Int32.Parse(medicalRecord_view.date_medical_examination_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng khám nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
            }
            else
            {
                medicalRecord.date_medical_examination_m = medicalRecord_view.date_medical_examination_m;
            }

            if (string.IsNullOrEmpty(medicalRecord_view.date_medical_examination_y) || Int32.Parse(medicalRecord_view.date_medical_examination_y) < 1900)
            {
                medicalRecord.date_medical_examination_y = "1900";
            }
            else if (medicalRecord_view.date_medical_examination_y.Length > 4 || medicalRecord_view.date_medical_examination_y.Length < 4 || medicalRecord_view.date_medical_examination_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm khám  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
            }
            else
            {
                medicalRecord.date_medical_examination_y = medicalRecord_view.date_medical_examination_y;
            }
            medicalRecord.date_medical_examination = DateTime.ParseExact((medicalRecord.date_medical_examination_d + "/" + medicalRecord.date_medical_examination_m + "/" + medicalRecord.date_medical_examination_y), "dd/MM/yyyy", null);


            medicalRecord.medical_status = medicalRecord_view.medical_status;
            medicalRecord.weights = medicalRecord_view.weights;
            medicalRecord.height = medicalRecord_view.height;
            medicalRecord.hospital = medicalRecord_view.hospital;
            medicalRecord.address_examination = medicalRecord_view.address_examination;
            medicalRecord.blood_group = medicalRecord_view.blood_group;
            medicalRecord.major_disease = medicalRecord_view.major_disease;
            medicalRecord.descriptions = medicalRecord_view.descriptions;
            medicalRecord.created_date = medicalRecord_view.created_date;
            medicalRecord.created_by = medicalRecord_view.created_by;
            medicalRecord.modified_date = medicalRecord_view.modified_date;
            medicalRecord.modified_by = medicalRecord_view.modified_by;   
            

            int new_id = h_contentModels.createMedicalRecord(medicalRecord);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo hồ sơ mới thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + medicalRecord.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo hồ sơ mới lỗi lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
            }
        }
        //Cập nhật hồ sơ sức khỏe
        public ActionResult edit_employee_medicalRecord()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_medicalRecord(int? id)
        {
            ViewBag.isAdd = false;
            var medicalRecord_view = new ViewModels.EmployeeMedicalRecordsViewModels();
            var medicalRecord = h_contentModels.getMedicalRecordByID(id ?? 0);
            if (medicalRecord != null)
            {
                medicalRecord_view.medical_records_id = medicalRecord.medical_records_id;
                medicalRecord_view.employee_id = medicalRecord.employee_id;
                //medicalRecord_view.date_medical_examination = medicalRecord.date_medical_examination;
                medicalRecord_view.date_medical_examination_d = medicalRecord.date_medical_examination_d;
                medicalRecord_view.date_medical_examination_m = medicalRecord.date_medical_examination_m;
                medicalRecord_view.date_medical_examination_y = medicalRecord.date_medical_examination_y;
                medicalRecord_view.medical_status = medicalRecord.medical_status;
                medicalRecord_view.weights = medicalRecord.weights;
                medicalRecord_view.height = medicalRecord.height;
                medicalRecord_view.hospital = medicalRecord.hospital;
                medicalRecord_view.address_examination = medicalRecord.address_examination;
                medicalRecord_view.blood_group = medicalRecord.blood_group;
                medicalRecord_view.major_disease = medicalRecord.major_disease;
                medicalRecord_view.descriptions = medicalRecord.descriptions;
                medicalRecord_view.created_date = medicalRecord.created_date;
                medicalRecord_view.created_by = medicalRecord.created_by;
                medicalRecord_view.modified_date = medicalRecord.modified_date;
                medicalRecord_view.modified_by = medicalRecord.modified_by;  
               
            }


            return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_medicalRecord(FormCollection collection)
        {
            var medicalRecord_view = new ViewModels.EmployeeMedicalRecordsViewModels();
            TryUpdateModel(medicalRecord_view);
            var medicalRecord = h_contentModels.getMedicalRecordByID(medicalRecord_view.medical_records_id ?? 0);

            medicalRecord.employee_id = medicalRecord_view.employee_id;
            //medicalRecord.date_medical_examination = medicalRecord_view.date_medical_examination;
            if (string.IsNullOrEmpty(medicalRecord_view.date_medical_examination_d) || medicalRecord_view.date_medical_examination_d == "0")
            {
                medicalRecord.date_medical_examination_d = "01";
            }
            else if (medicalRecord_view.date_medical_examination_d.Length == 1)
            {
                medicalRecord.date_medical_examination_d = "0" + medicalRecord_view.date_medical_examination_d;
            }
            else if (Int32.Parse(medicalRecord_view.date_medical_examination_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày khám nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
            }
            else
            {
                medicalRecord.date_medical_examination_d = medicalRecord_view.date_medical_examination_d;
            }
            if (string.IsNullOrEmpty(medicalRecord_view.date_medical_examination_m) || medicalRecord_view.date_medical_examination_m == "0")
            {
                medicalRecord.date_medical_examination_m = "01";
            }
            else if (medicalRecord_view.date_medical_examination_m.Length == 1)
            {
                medicalRecord.date_medical_examination_m = "0" + medicalRecord_view.date_medical_examination_m;
            }
            else if (Int32.Parse(medicalRecord_view.date_medical_examination_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng khám nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
            }
            else
            {
                medicalRecord.date_medical_examination_m = medicalRecord_view.date_medical_examination_m;
            }

            if (string.IsNullOrEmpty(medicalRecord_view.date_medical_examination_y) || Int32.Parse(medicalRecord_view.date_medical_examination_y) < 1900)
            {
                medicalRecord.date_medical_examination_y = "1900";
            }
            else if (medicalRecord_view.date_medical_examination_y.Length > 4 || medicalRecord_view.date_medical_examination_y.Length < 4 || medicalRecord_view.date_medical_examination_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm khám  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_medicalRecord", medicalRecord_view);
            }
            else
            {
                medicalRecord.date_medical_examination_y = medicalRecord_view.date_medical_examination_y;
            }
            medicalRecord.date_medical_examination = DateTime.ParseExact((medicalRecord.date_medical_examination_d + "/" + medicalRecord.date_medical_examination_m + "/" + medicalRecord.date_medical_examination_y), "dd/MM/yyyy", null);

            medicalRecord.medical_status = medicalRecord_view.medical_status;
            medicalRecord.weights = medicalRecord_view.weights;
            medicalRecord.height = medicalRecord_view.height;
            medicalRecord.hospital = medicalRecord_view.hospital;
            medicalRecord.address_examination = medicalRecord_view.address_examination;
            medicalRecord.blood_group = medicalRecord_view.blood_group;
            medicalRecord.major_disease = medicalRecord_view.major_disease;
            medicalRecord.descriptions = medicalRecord_view.descriptions;
            medicalRecord.created_date = medicalRecord_view.created_date;
            medicalRecord.created_by = medicalRecord_view.created_by;
            medicalRecord.modified_date = medicalRecord_view.modified_date;
            medicalRecord.modified_by = medicalRecord_view.modified_by;


            h_contentModels.edit_employee_medical_record(medicalRecord);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/" + medicalRecord.medical_records_id + "/" + medicalRecord.employee_id;
            return PartialView("../Shared/control_redirect");
        }

        //Thêm hồ sơ nghỉ việc
        public ActionResult add_employee_jobSeverance()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_employee_jobSeverance(int? id)
        {
            ViewBag.isAdd = true;
            var jobSeverance_view = new ViewModels.EmployeeJobSeveranceViewModels();
            jobSeverance_view.employee_id = id;
            return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_employee_jobSeverance(FormCollection collection)
        {
            var jobSeverance_view = new ViewModels.EmployeeJobSeveranceViewModels();
            TryUpdateModel(jobSeverance_view);

            web.data.entities.employee_job_severance jobSeverance = new data.entities.employee_job_severance();
            jobSeverance.employee_id = jobSeverance_view.employee_id;
            jobSeverance.form_job_severance = jobSeverance_view.form_job_severance;
            //jobSeverance.date_job_severance = jobSeverance.date_job_severance;
            if (string.IsNullOrEmpty(jobSeverance_view.date_job_severance_d) || jobSeverance_view.date_job_severance_d == "0")
            {
                jobSeverance.date_job_severance_d = "01";
            }
            else if (jobSeverance_view.date_job_severance_d.Length == 1)
            {
                jobSeverance.date_job_severance_d = "0" + jobSeverance_view.date_job_severance_d;
            }
            else if (Int32.Parse(jobSeverance_view.date_job_severance_d) > 31)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Ngày thôi việc nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
            }
            else
            {
                jobSeverance.date_job_severance_d = jobSeverance_view.date_job_severance_d;
            }
            if (string.IsNullOrEmpty(jobSeverance_view.date_job_severance_m) || jobSeverance_view.date_job_severance_m == "0")
            {
                jobSeverance.date_job_severance_m = "01";
            }
            else if (jobSeverance_view.date_job_severance_m.Length == 1)
            {
                jobSeverance.date_job_severance_m = "0" + jobSeverance_view.date_job_severance_m;
            }
            else if (Int32.Parse(jobSeverance_view.date_job_severance_m) > 12)
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tháng thôi việc nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
            }
            else
            {
                jobSeverance.date_job_severance_m = jobSeverance_view.date_job_severance_m;
            }

            if (string.IsNullOrEmpty(jobSeverance_view.date_job_severance_y) || Int32.Parse(jobSeverance_view.date_job_severance_y) < 1900)
            {
                jobSeverance.date_job_severance_y = "1900";
            }
            else if (jobSeverance_view.date_job_severance_y.Length > 4 || jobSeverance_view.date_job_severance_y.Length < 4 || jobSeverance_view.date_job_severance_y == "0000")
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Năm thôi việc  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
            }
            else
            {
                jobSeverance.date_job_severance_y = jobSeverance_view.date_job_severance_y;
            }
            jobSeverance.date_job_severance = DateTime.ParseExact((jobSeverance.date_job_severance_d + "/" + jobSeverance.date_job_severance_m + "/" + jobSeverance.date_job_severance_y), "dd/MM/yyyy", null);

            jobSeverance.subsidy = jobSeverance_view.subsidy;
            jobSeverance.refund_fee_education = jobSeverance_view.refund_fee_education;
            jobSeverance.compensation = jobSeverance_view.compensation;
            jobSeverance.created_date = jobSeverance_view.created_date;
            jobSeverance.created_by = jobSeverance_view.created_by;
            jobSeverance.modified_date = jobSeverance_view.modified_date;
            jobSeverance.modified_by = jobSeverance_view.modified_by;


            int new_id = h_contentModels.createJobSeverance(jobSeverance);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo hồ sơ nghỉ việc thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/profile/detail_profile/" + jobSeverance.employee_id;
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.result_message = "Tạo hồ sơ nghỉ việc bị lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
            }
        }

        //Cập nhật hồ sơ nghỉ việc
        public ActionResult edit_employee_jobSeverance()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_employee_jobSeverance(int? id)
        {
            ViewBag.isAdd = false;
            var jobSeverance_view = new ViewModels.EmployeeJobSeveranceViewModels();
            var jobSeverance = h_contentModels.getJobSeveranceByID(id ?? 0);
            if (jobSeverance != null)
            {
                jobSeverance_view.job_severance_id = jobSeverance.job_severance_id;
                jobSeverance_view.employee_id = jobSeverance.employee_id;
                jobSeverance_view.form_job_severance = jobSeverance.form_job_severance;
                //jobSeverance_view.date_job_severance = jobSeverance.date_job_severance;
                jobSeverance_view.date_job_severance_d = jobSeverance.date_job_severance_d;
                jobSeverance_view.date_job_severance_m = jobSeverance.date_job_severance_m;
                jobSeverance_view.date_job_severance_y = jobSeverance.date_job_severance_y;
                //jobSeverance_view.subsidy = double.Parse(jobSeverance.subsidy).ToString();
                //jobSeverance_view.refund_fee_education = Convert.ToDouble(jobSeverance.refund_fee_education);
                //jobSeverance_view.compensation = jobSeverance.compensation;
                jobSeverance_view.created_date = jobSeverance.created_date;
                jobSeverance_view.created_by = jobSeverance.created_by;
                jobSeverance_view.modified_date = jobSeverance.modified_date;
                jobSeverance_view.modified_by = jobSeverance.modified_by;

            }


            return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_employee_jobSeverance(FormCollection collection)
        {
            var jobSeverance_view = new ViewModels.EmployeeJobSeveranceViewModels();
            TryUpdateModel(jobSeverance_view);
            var jobSeverance = h_contentModels.getJobSeveranceByID(jobSeverance_view.job_severance_id ?? 0);

            jobSeverance.employee_id = jobSeverance_view.employee_id;
            jobSeverance_view.form_job_severance = jobSeverance_view.form_job_severance;
            //jobSeverance_view.date_job_severance = jobSeverance.date_job_severance;
            if (string.IsNullOrEmpty(jobSeverance_view.date_job_severance_d) || jobSeverance_view.date_job_severance_d == "0")
            {
                jobSeverance.date_job_severance_d = "01";
            }
            else if (jobSeverance_view.date_job_severance_d.Length == 1)
            {
                jobSeverance.date_job_severance_d = "0" + jobSeverance_view.date_job_severance_d;
            }
            else if (Int32.Parse(jobSeverance_view.date_job_severance_d) > 31)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Ngày thôi việc nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
            }
            else
            {
                jobSeverance.date_job_severance_d = jobSeverance_view.date_job_severance_d;
            }
            if (string.IsNullOrEmpty(jobSeverance_view.date_job_severance_m) || jobSeverance_view.date_job_severance_m == "0")
            {
                jobSeverance.date_job_severance_m = "01";
            }
            else if (jobSeverance_view.date_job_severance_m.Length == 1)
            {
                jobSeverance.date_job_severance_m = "0" + jobSeverance_view.date_job_severance_m;
            }
            else if (Int32.Parse(jobSeverance_view.date_job_severance_m) > 12)
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Tháng thôi việc nhập chưa đúng";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
            }
            else
            {
                jobSeverance.date_job_severance_m = jobSeverance_view.date_job_severance_m;
            }

            if (string.IsNullOrEmpty(jobSeverance_view.date_job_severance_y) || Int32.Parse(jobSeverance_view.date_job_severance_y) < 1900)
            {
                jobSeverance.date_job_severance_y = "1900";
            }
            else if (jobSeverance_view.date_job_severance_y.Length > 4 || jobSeverance_view.date_job_severance_y.Length < 4 || jobSeverance_view.date_job_severance_y == "0000")
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Năm thôi việc  nhập chưa chính xác";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_employee_jobSeverance", jobSeverance_view);
            }
            else
            {
                jobSeverance.date_job_severance_y = jobSeverance_view.date_job_severance_y;
            }
            jobSeverance.date_job_severance = DateTime.ParseExact((jobSeverance.date_job_severance_d + "/" + jobSeverance.date_job_severance_m + "/" + jobSeverance.date_job_severance_y), "dd/MM/yyyy", null);

            //jobSeverance_view.subsidy = double.Parse(jobSeverance.subsidy).ToString();
            //jobSeverance_view.refund_fee_education = Convert.ToDouble(jobSeverance.refund_fee_education);
            //jobSeverance_view.compensation = jobSeverance.compensation;
            jobSeverance.created_date = jobSeverance_view.created_date;
            jobSeverance.created_by = jobSeverance_view.created_by;
            jobSeverance.modified_date = jobSeverance_view.modified_date;
            jobSeverance.modified_by = jobSeverance_view.modified_by;


            h_contentModels.edit_employee_jobSeverance(jobSeverance);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/detail_profile/" + jobSeverance.employee_id;
            return PartialView("../Shared/control_redirect");
        }

     
        //danh sách kỷ luật
        public ActionResult list_discripline()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_discripline(int? id, string text_search, DateTime? from_date, DateTime? to_date)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            return control_list_discripline(id ?? 1, 10, text_search,from_date, to_date);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_discripline(int? id, int? pagesize, string text_search,DateTime? from_date, DateTime? to_date)
        {
            var discripline_view = new ViewModels.PageListDisciplineViewModels();
            TryUpdateModel(discripline_view);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            id = id ?? 1;
            discripline_view.list_pagesize = sizeDrop;
            discripline_view.pagesize = pagesize ?? 10;
            discripline_view.from_date = from_date;
            discripline_view.to_date = to_date;
            discripline_view.text_search = text_search;
            discripline_view.page_list_discipline = h_contentModels.getPagerDiscripline(id ?? 1, pagesize ?? 10, text_search ?? null, from_date,  to_date);
            return PartialView("../Shared/control_list_discripline", discripline_view);
        }
        public ActionResult list_discripline_export(int? type, string text_search, int? years,DateTime? from_date, DateTime? to_date)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            Document document = new Document(PageSize.A4, 40, 40, 40,40);
            var list_discripline = h_contentModels.getPagerDiscriplineExport(text_search ?? null, years, from_date,  to_date);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_ky_luat_" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_ky_luat_" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<table border='0' cellspacing='0' style=\"width:29.7cm;height:21cm;\">");

            sb.Append("<tr>");
            sb.Append("<td colspan=\"6\" style=\"text-align:left;font-weight:bold;padding-bottom:10px;\">");
            sb.Append("Công ty ADCC");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"6\" style=\"text-align:center;text-transform:uppercase;font-weight:bold;\" >DANH SÁCH KỶ LUẬT CÁ NHÂN, TẬP THỂ</td>");
            sb.Append("</tr>");
            sb.Append("<tr><td colspan=\"6\" style=\"text-align:center;font-weight:bold;padding-bottom:30px;\">Từ:" + (from_date.Value.Month + "/" + from_date.Value.Year + " Đến:" + to_date.Value.Month + "/" + to_date.Value.Year) + "</td></tr>");
            sb.Append("<tr>");
            sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;border-left:1px solid #ccc;text-align:center;width:80px;\">STT<br/></td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:350px;\">Đơn vị, họ tên(cấp bậc, chức vụ, đơn vị)<br/></td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:200px;\">QUYẾT ĐỊNH<br/>(số,ngày,tháng,năm)</td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:200px;\">Hình thức phạt<br/></td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:250px;\">Lý do phạt<br/></td>");
            sb.Append("</tr>");
            for (int i = 0; i < list_discripline.Count; i++)
            {
                var index = i + 1;
                sb.Append("<tr>");
                var employee = profileModels.getEmployeeByID(list_discripline[i].employee_id ?? 0);
                var de = h_contentModels.getDepartmentsByID(list_discripline[i].departments_id ?? 0);
                string em_name = "";
               string de_name = "";
                string group_name="";
                group_name = list_discripline[i].reward_name_group;
                if(employee!=null){
                    em_name = employee.full_name  + "<br/> - Chức vụ" + employee.positions + "<br/> - Cấp bậc" + employee.ranks;
                }
                if(de!=null){ 
                    if(group_name!=null){
                        de_name = de.departments_name + "<br/> - " + group_name;
                    }else{
                        de_name = de.departments_name;
                    }
                    
                }else if(de==null){
                    de_name = group_name;
                }
                

                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-left:1px solid #ccc;\">" + index + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;\">" + em_name + de_name + " </td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;\">" + list_discripline[i].reward_number + "," + String.Format("{0:dd/MM/yyyy}", list_discripline[i].signature_date) + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;\">" + list_discripline[i].reward_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;\">" + list_discripline[i].descriptions + "</td>");
                sb.Append("</tr>");
            }
            string test = sb.ToString();
            sb.Append("<tr><td colspan=\"6\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            sb.Append("<tr><td colspan=\"6\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");
            //sb.Append("</div>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_discripline", new { id = 1, text_search = text_search, years = years });
        }

        //Thêm danh sách kỷ luật
        public ActionResult add_discripline()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_discripline(int? id)
        {
            ViewBag.isAdd = true;
            var discripline_view = new ViewModels.PageListDisciplineViewModels();
            discripline_view.list_employees = h_contentModels.getListEmployeesBirthday();
            discripline_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            return PartialView("../Shared/control_detail_discripline", discripline_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_discripline(FormCollection collection)
        {
            var discripline_view = new ViewModels.PageListDisciplineViewModels();
            TryUpdateModel(discripline_view);
            discripline_view.list_employees = h_contentModels.getListEmployeesBirthday();
            discripline_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            web.data.entities.reward discripline = new data.entities.reward();
            
            discripline.type_reward = 3;
            discripline.reward_number = discripline_view.reward_number;
            discripline.descriptions = discripline_view.descriptions;
            discripline.reward_name = discripline_view.reward_name;
            discripline.signature_name = discripline_view.signature_name;
            discripline.signature_date = discripline_view.signature_date??DateTime.Now;
            discripline.is_collective = discripline_view.is_collective;
            if (discripline.is_collective == 1) {
                discripline.reward_name_group = null;
                discripline.departments_id = null;
                if (discripline_view.employee_id == null)
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Xin chọn người bị kỷ luật.";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_discripline", discripline_view);
                }else
                {
                    discripline.employee_id = discripline_view.employee_id;
                }
                
            }
            else if (discripline.is_collective == 2)
            {
                
                if (discripline_view.departments_id == null)
                {
                    if (string.IsNullOrEmpty(discripline_view.reward_name_group))
                    {
                        ViewBag.isAdd = true;
                        ViewBag.result_message = "Xin chọn đơn vị bị hoặc điền nhóm bị kỷ luật.";
                        ViewBag.result = false;
                        return PartialView("../Shared/control_detail_discripline", discripline_view);
                    }
                    else {
                        discripline.reward_name_group = discripline_view.reward_name_group;
                        discripline.departments_id = null;
                    }
                }
                else
                {
                    discripline.reward_name_group = discripline_view.reward_name_group;
                    discripline.departments_id = discripline_view.departments_id;   
                }
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Xin vui lòng chọn đối tượng kỷ luật.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_discripline", discripline_view);
            }
            discripline.reward_name_group = discripline_view.reward_name_group;
            discripline.reward_status = discripline_view.reward_status;


            int new_id = h_contentModels.createDiscripline(discripline);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo hồ sơ nghỉ việc thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_discripline";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tạo hồ sơ nghỉ việc bị lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_discripline", discripline_view);
            }
        }
        //Cập nhật danh sách kỷ luật
        public ActionResult edit_discripline()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_discripline(int? id)
        {
            ViewBag.isAdd = false;
            var discripline_view = new ViewModels.PageListDisciplineViewModels();
            discripline_view.list_employees = h_contentModels.getListEmployeesBirthday();
            discripline_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            var discripline = h_contentModels.getDiscriplinedByID(id ?? 0);
            if (discripline != null)
            {
                discripline_view.reward_id = discripline.reward_id;
                discripline_view.employee_id = discripline.employee_id;
                discripline_view.departments_id = discripline.departments_id;
                discripline_view.reward_number = discripline.reward_number;
                discripline_view.signature_name = discripline.signature_name;
                discripline_view.signature_date = discripline.signature_date;
                discripline_view.descriptions = discripline.descriptions;
                discripline_view.reward_name = discripline.reward_name;
                discripline_view.is_collective = discripline.is_collective;
                discripline_view.reward_name_group = discripline.reward_name_group;
                discripline_view.reward_status = discripline.reward_status;

            }
            return PartialView("../Shared/control_detail_discripline", discripline_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_discripline(FormCollection collection)
        {
            var discripline_view = new ViewModels.PageListDisciplineViewModels();
            discripline_view.list_employees = h_contentModels.getListEmployeesBirthday();
            discripline_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            TryUpdateModel(discripline_view);
            var discripline = h_contentModels.getDiscriplinedByID(discripline_view.reward_id ?? 0);

            discripline.reward_number = discripline_view.reward_number;
            discripline.descriptions = discripline_view.descriptions;
            discripline.reward_name = discripline_view.reward_name;
            discripline.signature_name = discripline_view.signature_name;
            discripline.signature_date = discripline_view.signature_date ?? DateTime.Now;
            discripline.is_collective = discripline_view.is_collective;
            if (discripline.is_collective == 1)
            {
                discripline.reward_name_group = null;
                discripline.departments_id = null;
                if (discripline_view.employee_id == null)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Xin chọn người bị kỷ luật.";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_discripline", discripline_view);
                }
                else
                {
                    discripline.employee_id = discripline_view.employee_id;
                }

            }
            else if (discripline.is_collective == 2)
            {

                if (discripline_view.departments_id == null)
                {
                    if (string.IsNullOrEmpty(discripline_view.reward_name_group))
                    {
                        ViewBag.isAdd = false;
                        ViewBag.result_message = "Xin chọn đơn vị bị hoặc điền nhóm bị kỷ luật.";
                        ViewBag.result = false;
                        return PartialView("../Shared/control_detail_discripline", discripline_view);
                    }
                    else
                    {
                        discripline.reward_name_group = discripline_view.reward_name_group;
                        discripline.departments_id = null;
                    }
                }
                else
                {
                    discripline.reward_name_group = discripline_view.reward_name_group;
                    discripline.departments_id = discripline_view.departments_id;
                }
            }
            else
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Xin vui lòng chọn đối tượng kỷ luật.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_discripline", discripline_view);
            }
            discripline.reward_name_group = discripline_view.reward_name_group;
            discripline.reward_status = discripline_view.reward_status;



            h_contentModels.edit_discripline(discripline);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_discripline";
            return PartialView("../Shared/control_redirect");
        }
        //Danh sách huân huy chương
        public ActionResult list_medals()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_medals(int? id, string text_search, int? years, DateTime? from_date, DateTime? to_date)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            return control_list_medals(id ?? 1, 10, text_search, years??0,from_date,to_date);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_medals(int? id, int? pagesize, string text_search, int? years,DateTime? from_date, DateTime? to_date)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            var medals_view = new ViewModels.PageListMedalsViewModels();
            TryUpdateModel(medals_view);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            id = id ?? 1;
            medals_view.list_pagesize = sizeDrop;
            medals_view.pagesize = pagesize ?? 10;
            medals_view.text_search = text_search;
            medals_view.from_date = from_date;
            medals_view.to_date = to_date;
            medals_view.text_search = text_search;
            medals_view.list_years = h_contentModels.getListYears();

            medals_view.page_list_medals = h_contentModels.getPagerMedals(id ?? 1, pagesize ?? 10, text_search ?? null,years,from_date,to_date);
            return PartialView("../Shared/control_list_medals", medals_view);
        }

        //Danh sách huân huy chương cho tập thể
        public ActionResult list_medals_group()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_medals_group(int? id, string text_search, int? years, DateTime? from_date, DateTime? to_date)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            return control_list_medals_group(id ?? 1, 10, text_search, years ?? 0,from_date,to_date);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_medals_group(int? id, int? pagesize, string text_search, int? years, DateTime? from_date, DateTime? to_date)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            var medals_group_view = new ViewModels.PageListMedalsViewModels();
            TryUpdateModel(medals_group_view);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            id = id ?? 1;
            medals_group_view.list_pagesize = sizeDrop;
            medals_group_view.pagesize = pagesize ?? 10;
            medals_group_view.text_search = text_search;
            medals_group_view.from_date = from_date;
            medals_group_view.to_date = to_date;
            medals_group_view.list_years_group = h_contentModels.getListYearsGroup();

            medals_group_view.page_list_medals_group = h_contentModels.getPagerMedalsGroup(id ?? 1, pagesize ?? 10, text_search ?? null, years,from_date,to_date);
            return PartialView("../Shared/control_list_medals_group", medals_group_view);
        }



        public ActionResult list_medals_CN_export(int? type, string text_search, int? years, DateTime? from_date, DateTime? to_date)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            Document document = new Document(PageSize.A4, 40, 40, 40, 40);
            var list_medals_CN = h_contentModels.getPagerMedalsCNExport(text_search ?? null, years,from_date, to_date);
            
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_huan_huy_chuong" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_huan_huy_chuong" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            { 
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=Danh_sach_huan_huy_chuong" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            //Response.Write("@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            //Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            StringBuilder sb = new StringBuilder();
            //sb.Append("<div style=\"size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:0.75in 0.75in 0.75in 0.75in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;\">");
            //sb.Append("<div style=\"size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:0.75in 0.75in 0.75in 0.75in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;\">");
            sb.Append("<table border='0' cellspacing='0' style=\"width:29.7cm;height:21cm;\">");
      
            sb.Append("<tr>");
            sb.Append("<td colspan=\"9\" style=\"text-align:left;font-weight:bold;padding-bottom:10px;\">");
            sb.Append("Công ty ADCC");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            
                sb.Append("<td colspan=\"9\" style=\"text-align:center;text-transform:uppercase;font-weight:bold;\" >DANH SÁCH TẶNG THƯỞNG HUÂN,HUY CHƯƠNG ĐỐI VỚI CÁ NHÂN</td>");
                sb.Append("</tr>");
                sb.Append("<tr><td colspan=\"9\" style=\"text-align:center;text-transform:uppercase;font-weight:bold;padding-bottom:30px;\">Từ:" + (from_date.Value.Month + "/" + from_date.Value.Year + " Đến:" + to_date.Value.Month + "/" + to_date.Value.Year) + "</td></tr>");
                sb.Append("<tr>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;border-left:1px solid #ccc;text-align:center;width:50px;\">STT<br/></td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:150px;\">CẤP BẬC - HỌ VÀ TÊN<br/></td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:100px;\">CHỨC VỤ - ĐƠN VỊ<br/></td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:150px;\">QUÊ QUÁN<br/>(xã,huyện,tỉnh)</td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:100px;\">LOẠI HUÂN CHƯƠNG</td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:60px;\">HẠNG<br/></td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:100px;\">QUYẾT ĐỊNH<br/>(số,ngày,tháng,năm)</td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:100px;\">NGƯỜI KÝ<br/></td>")
                .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:150px;\">THÀNH TÍCH<br/></td>");
                sb.Append("</tr>");

            for (int i = 0; i < list_medals_CN.Count; i++)
            {
                string tm_name = "";
                if (!string.IsNullOrEmpty(list_medals_CN[i].type_medals))
                {
                    var tm = h_contentModels.getTypeRewardByID(int.Parse(list_medals_CN[i].type_medals));
                    if (tm != null)
                    {
                        tm_name = tm.type_reward_name;
                    }
                }
                string mc_name = "";
                if (!string.IsNullOrEmpty(list_medals_CN[i].type_medals))
                {
                    var mc = h_contentModels.getTypeRewardByID(int.Parse(list_medals_CN[i].medal_class));
                    if (mc != null)
                    {
                        mc_name = mc.type_reward_name;
                    }
                }
                var index = i + 1;
                var employee = profileModels.getEmployeeByID(list_medals_CN[i].employee_id ?? 0);

                var depr = profileModels.getDepartmentByID(list_medals_CN[i].departments_id ?? 0);


                list_medals_CN[i].employee_id = list_medals_CN[i].employee_id ?? 0;    
                var nhanvien = employee.ranks + "<br/>" + employee.full_name ?? " ";
                sb.Append("<tr>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-left:1px solid #ccc;\">" + index + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + nhanvien + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + employee.positions + "-" + "Cty ADCC" + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + employee.hometown + "</td>");
               
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + tm_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + mc_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + list_medals_CN[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_medals_CN[i].signature_date) + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + list_medals_CN[i].signature_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + list_medals_CN[i].descriptions + "</td>");
                sb.Append("</tr>");
            }
            string test = sb.ToString();
            sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");
            //sb.Append("</div>");
            
            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_medals_CN", new { id = 1, text_search = text_search, years = years });
        }

        public ActionResult list_medals_TT_export(int? type, string text_search, int? years, DateTime? from_date, DateTime? to_date)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            Document document = new Document(PageSize.A4, 40, 40, 40, 40);
            var list_medals_TT = h_contentModels.getPagerMedalsTTExport(text_search ?? null, years,from_date,to_date);

            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_huan_huy_chuong" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_huan_huy_chuong" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=Danh_sach_huan_huy_chuong" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            //Response.Write("@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            //Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            StringBuilder sb = new StringBuilder();
            //sb.Append("<div style=\"size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:0.75in 0.75in 0.75in 0.75in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;\">");
            //sb.Append("<div style=\"size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:0.75in 0.75in 0.75in 0.75in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;\">");
            sb.Append("<table border='0' cellspacing='0' style=\"width:29.7cm;height:21cm;\">");

            sb.Append("<tr>");
            sb.Append("<td colspan=\"9\" style=\"text-align:left;font-weight:bold;padding-bottom:10px;\">");
            sb.Append("Công ty ADCC");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"9\" style=\"text-align:center;text-transform:uppercase;font-weight:bold;\" >DANH SÁCH TẶNG THƯỞNG HUÂN,HUY CHƯƠNG ĐỐI VỚI TẬP THỂ</td>");
            sb.Append("</tr>");
            sb.Append("<tr><td colspan=\"9\" style=\"text-align:center;text-transform:uppercase;font-weight:bold;padding-bottom:30px;\">Từ:" + (from_date.Value.Month + "/" + from_date.Value.Year + " Đến:" + to_date.Value.Month + "/" + to_date.Value.Year) + "</td></tr>");
            sb.Append("<tr>");
            sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;border-left:1px solid #ccc;text-align:center;width:50px;\">STT<br/></td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:150px;\">TÊN ĐƠN VỊ (PHÒNG BAN)<br/></td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:100px;\">LOẠI HUÂN CHƯƠNG</td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:60px;\">HẠNG<br/></td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:100px;\">QUYẾT ĐỊNH<br/>(số,ngày,tháng,năm)</td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:100px;\">NGƯỜI KÝ<br/></td>")
            .Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-top:1px solid #ccc;width:150px;\">THÀNH TÍCH<br/></td>");
            sb.Append("</tr>");

            for (int i = 0; i < list_medals_TT.Count; i++)
            {
                string tm_name = "";
                if (!string.IsNullOrEmpty(list_medals_TT[i].type_medals))
                {
                    var tm = h_contentModels.getTypeRewardByID(int.Parse(list_medals_TT[i].type_medals));
                    if (tm != null)
                    {
                        tm_name = tm.type_reward_name;
                    }
                }
                string mc_name = "";
                if (!string.IsNullOrEmpty(list_medals_TT[i].type_medals))
                {
                    var mc = h_contentModels.getTypeRewardByID(int.Parse(list_medals_TT[i].medal_class));
                    if (mc != null)
                    {
                        mc_name = mc.type_reward_name;
                    }
                }
                var index = i + 1;
                var employee = profileModels.getEmployeeByID(list_medals_TT[i].employee_id ?? 0);

                var depr = profileModels.getDepartmentByID(list_medals_TT[i].departments_id ?? 0);
                var depr_name = depr.departments_name + "<br/> -" + list_medals_TT[i].reward_name_group;
                sb.Append("<tr>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;border-left:1px solid #ccc;\">" + index + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:left;\">" + depr_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + tm_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + mc_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + list_medals_TT[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_medals_TT[i].signature_date) + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + list_medals_TT[i].signature_name + "</td>");
                sb.Append("<td style=\"border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center;\">" + list_medals_TT[i].descriptions + "</td>");
                sb.Append("</tr>");
            }
            string test = sb.ToString();
            sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");
            //sb.Append("</div>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_medals_TT", new { id = 1, text_search = text_search, years = years });
        }
        //Khen thuong
        public ActionResult add_reward()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_reward(int? id)
        {
            ViewBag.isAdd = true;
            var reward_view = new ViewModels.PageListRewardViewModels();
            reward_view.list_employees = h_contentModels.getListEmployeesBirthday();
            reward_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
           
            return PartialView("../Shared/control_detail_reward", reward_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_reward(FormCollection collection)
        {
            var reward_view = new ViewModels.PageListRewardViewModels();
            TryUpdateModel(reward_view);
            reward_view.list_employees = h_contentModels.getListEmployeesBirthday();
            reward_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            web.data.entities.reward reward = new data.entities.reward();

            reward.type_reward = 1;
            reward.skill_reward = reward_view.skill_reward;
            reward.reward_number = reward_view.reward_number;
            reward.form_reward = reward_view.form_reward;
            reward.descriptions = reward_view.descriptions;
            reward.reward_name = reward_view.reward_name;
            reward.signature_name = reward_view.signature_name;
            reward.signature_date = reward_view.signature_date ?? DateTime.Now;
            reward.is_collective = reward_view.is_collective;
            if (reward.is_collective == 1)
            {
                reward.reward_name_group = null;
                reward.departments_id = null;
                reward.employee_id = reward_view.employee_id;
            }
            else if (reward.is_collective == 2)
            {
                reward.reward_name_group = reward_view.reward_name_group;
                reward.departments_id = reward_view.departments_id;
                reward.employee_id = null;
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Xin vui lòng chọn đối tượng khen thưởng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_reward", reward_view);
            }
            reward.reward_name_group = reward_view.reward_name_group;
            reward.reward_status = reward_view.reward_status;


            int new_id = h_contentModels.createReward (reward);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo khen thưởng thành công.";
                ViewBag.result = true;
                //if (reward.is_collective == 1) {
                //    ViewBag.redirect = "/vi/h_content/add_reward/";
                //}
                //else if (reward.is_collective == 2) { ViewBag.redirect = "/vi/h_content/add_reward/"; }
                //return PartialView("../Shared/control_redirect");
                return PartialView("../Shared/control_detail_reward", reward_view);
                //reward_view.reward_id = null;
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tạo khen thưởng bị lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_reward", reward_view);
            }
        }
        public ActionResult edit_reward()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_reward(int? id)
        {
            ViewBag.isAdd = false;
            var reward_view = new ViewModels.PageListRewardViewModels();
            reward_view.list_employees = h_contentModels.getListEmployeesBirthday();
            reward_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            var reward = h_contentModels.getRewardByID(id ?? 0);
            if (reward != null)
            {
                reward_view.reward_id = reward.reward_id;
                reward_view.employee_id = reward.employee_id;
                reward_view.departments_id = reward.departments_id??0;
                reward_view.reward_number = reward.reward_number;
                reward_view.signature_name = reward.signature_name;
                reward_view.signature_date = reward.signature_date;
                reward_view.descriptions = reward.descriptions;
                reward_view.reward_name = reward.reward_name;
                reward_view.is_collective = reward.is_collective;
                reward_view.reward_name_group = reward.reward_name_group;
                reward_view.form_reward = reward.form_reward;
                reward_view.skill_reward = reward.skill_reward;
                reward_view.reward_status = reward.reward_status;

            }
            return PartialView("../Shared/control_detail_reward", reward_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_reward(FormCollection collection)
        {
            var reward_view = new ViewModels.PageListRewardViewModels();
            TryUpdateModel(reward_view);
            var reward = h_contentModels.getRewardByID(reward_view.reward_id ?? 0);

            reward.employee_id = reward_view.employee_id;
            reward.reward_number = reward_view.reward_number;
            reward.signature_name = reward_view.signature_name;
            reward.signature_date = reward_view.signature_date;
            reward.descriptions = reward_view.descriptions;
            reward.reward_name = reward_view.reward_name;
            reward.is_collective = reward_view.is_collective;
            reward.reward_name_group = reward_view.reward_name_group;
            reward.form_reward = reward_view.form_reward;
            if (reward.is_collective == 1)
            {
                reward.reward_name_group = null;
                reward.departments_id = null;
                reward.employee_id = reward_view.employee_id;
            }
            else if (reward.is_collective == 2)
            {
                reward.reward_name_group = reward_view.reward_name_group;
                reward.departments_id = reward_view.departments_id;
                reward.employee_id = null;
            }
            
            reward.skill_reward = reward_view.skill_reward;
            
            reward.reward_status = reward_view.reward_status;



            h_contentModels.edit_reward(reward);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            if (reward.is_collective == 1)
            {
                ViewBag.redirect = "/vi/profile/list_KT_CN";
            }
            else if (reward.is_collective == 2) { ViewBag.redirect = "/vi/profile/list_KT_TT"; }
            return PartialView("../Shared/control_redirect");
        }

        //Thêm tặng thưởng huân huy chương cho cá nhân
        public ActionResult add_medals()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_medals(int? id)
        {
            ViewBag.isAdd = true;
            
            var add_medals_view = new ViewModels.PageListMedalsViewModels();
            add_medals_view.list_employees = h_contentModels.getListEmployeesBirthday();
            add_medals_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            add_medals_view.list_type_meadals = h_contentModels.getListTypeRewardBuilder(null);
            return PartialView("../Shared/control_detail_medals", add_medals_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_medals(FormCollection collection)
        {
            var add_medals_view = new ViewModels.PageListMedalsViewModels();
            
            
            TryUpdateModel(add_medals_view);
            add_medals_view.list_employees = h_contentModels.getListEmployeesBirthday();
            add_medals_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            add_medals_view.list_type_meadals = h_contentModels.getListTypeRewardBuilder(null);
            web.data.entities.reward medals = new data.entities.reward();
            medals.is_collective = add_medals_view.is_collective;
            if (medals.is_collective == 1) 
            {
                if (add_medals_view.employee_id == null)
                {
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Bạn vui lòng chọn tên nhân viên.";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_medals", add_medals_view);
                }
                medals.departments_id = null;
                if(medals.employee_id==null){
                    ViewBag.isAdd = true;
                    ViewBag.result_message = "Bạn chưa chọn người được tặng thưởng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_medals", add_medals_view);
                }else{
                    medals.employee_id = add_medals_view.employee_id;
                }
                
                medals.type_reward = 2;
                if (add_medals_view.medals != null)
                { 
                    
                    var type_reward_obj=h_contentModels.getTypeRewardByID((int)add_medals_view.medals);
                    if (type_reward_obj != null)
                    {
                        var parent = type_reward_obj.parent_id;
                        
                        if (parent != null)
                        {
                            //medal select parent
                            var type_reward_parent = h_contentModels.getTypeRewardByID((int)parent);
                            //save parent id  to type_medals
                            medals.type_medals = type_reward_parent.type_reward_id.ToString();
                            //save child id to 
                            medals.medal_class = ((int)add_medals_view.medals).ToString();
                        }
                        else
                        {
                            //medal select not parent
                            medals.medal_class = null;
                            medals.type_medals = ((int)add_medals_view.medals).ToString();
                        }
                    }
                }
                else
                {
                    //medal select not parent
                    medals.medal_class = null;
                    medals.type_medals = null;
                }
                medals.reward_number = add_medals_view.reward_number;
                medals.signature_name = add_medals_view.signature_name;
                medals.signature_date = add_medals_view.signature_date;
                medals.descriptions = add_medals_view.descriptions;
                medals.Years = add_medals_view.years;
                medals.reward_name_group = null;
            }
            else if (medals.is_collective == 2)
            {
                medals.employee_id = null;
                if (add_medals_view.departments_id == null)
                {
                    if (string.IsNullOrEmpty(add_medals_view.reward_name_group))
                    {
                        ViewBag.isAdd = true;
                        ViewBag.result_message = "Xin chọn đơn vị hoặc điền nhóm được tặng thưởng";
                        ViewBag.result = false;
                        return PartialView("../Shared/control_detail_medals", add_medals_view);
                    }
                    else {
                        medals.reward_name_group = add_medals_view.reward_name_group;
                        medals.departments_id = null;
                    }
                }
                else {
                    medals.departments_id = add_medals_view.departments_id;
                    medals.reward_name_group = add_medals_view.reward_name_group;
                }
                medals.type_reward = 2;
                if (add_medals_view.medals != null)
                {

                    var type_reward_obj = h_contentModels.getTypeRewardByID((int)add_medals_view.medals);
                    if (type_reward_obj != null)
                    {
                        var parent = type_reward_obj.parent_id;

                        if (parent != null)
                        {
                            //medal select parent
                            var type_reward_parent = h_contentModels.getTypeRewardByID((int)parent);
                            //save parent id  to type_medals
                            medals.type_medals = type_reward_parent.type_reward_id.ToString();
                            //save child id to 
                            medals.medal_class = ((int)add_medals_view.medals).ToString();
                        }
                        else
                        {
                            //medal select not parent
                            medals.medal_class = null;
                            medals.type_medals = ((int)add_medals_view.medals).ToString();
                        }
                    }
                }
                else
                {
                    //medal select not parent
                    medals.medal_class = null;
                    medals.type_medals = null;
                }
                medals.reward_number = add_medals_view.reward_number;
                medals.signature_name = add_medals_view.signature_name;
                medals.signature_date = add_medals_view.signature_date;
                medals.descriptions = add_medals_view.descriptions;
                medals.Years = add_medals_view.years;
                
               // medals.is_collective = add_medals_view.is_collective;
            }
           
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Xin vui lòng chọn đối tặng thưởng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_medals", add_medals_view);
            }
            int new_id = h_contentModels.createMedals(medals);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo tặng thưởng huân huy chương thành công.";
                ViewBag.result = true;
                if (medals.is_collective == 1) 
                {
                    ViewBag.redirect = "/vi/h_content/list_medals";
                }
                else if (medals.is_collective == 2)
                {
                    ViewBag.redirect = "/vi/h_content/list_medals_group";
                }
                else {
                    ViewBag.result = false;
                }
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tạo tặng thưởng lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_medals", add_medals_view);
            }
        }

        //Cập nhật tặng huân huy 
        public ActionResult edit_medals()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_medals(int? id)
        {
            ViewBag.isAdd = false;
            var medals_view = new ViewModels.PageListMedalsViewModels();
            medals_view.list_employees = h_contentModels.getListEmployeesBirthday();
            medals_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            medals_view.list_type_meadals = h_contentModels.getListTypeRewardBuilder(null);
            var medals = h_contentModels.getMedalsByID(id ?? 0);
            if (medals != null)
            {
                medals_view.reward_id = medals.reward_id;
                medals_view.employee_id = medals.employee_id;
                medals_view.departments_id = medals.departments_id;
                medals_view.type_medals = medals.type_medals;
                medals_view.medal_class = medals.medal_class;
                medals_view.reward_number = medals.reward_number;
                medals_view.signature_name = medals.signature_name;
                medals_view.signature_date = medals.signature_date;
                medals_view.descriptions = medals.descriptions;
                medals_view.years = medals.Years;
                medals_view.reward_name_group = medals.reward_name_group;
                medals_view.is_collective = medals.is_collective;

            }


            return PartialView("../Shared/control_detail_medals", medals_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_medals(FormCollection collection)
        {
            var medals_view = new ViewModels.PageListMedalsViewModels();
            TryUpdateModel(medals_view);
            medals_view.list_employees = h_contentModels.getListEmployeesBirthday();
            medals_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            medals_view.list_type_meadals = h_contentModels.getListTypeRewardBuilder(null);
            var medals = h_contentModels.getMedalsByID(medals_view.reward_id ?? 0);

            medals.is_collective = medals_view.is_collective;
            if (medals.is_collective == 1) 
            {
                if (medals_view.employee_id == null)
                {
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Bạn vui lòng chọn tên nhân viên.";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_medals", medals_view);
                }
                medals.departments_id = null;
                if(medals.employee_id==null){
                    ViewBag.isAdd = false;
                    ViewBag.result_message = "Bạn chưa chọn người được tặng thưởng";
                    ViewBag.result = false;
                    return PartialView("../Shared/control_detail_medals", medals_view);
                }else{
                    medals.employee_id = medals_view.employee_id;
                }
                
                medals.type_reward = 2;
                if (medals_view.medals != null)
                {

                    var type_reward_obj = h_contentModels.getTypeRewardByID((int)medals_view.medals);
                    if (type_reward_obj != null)
                    {
                        var parent = type_reward_obj.parent_id;

                        if (parent != null)
                        {
                            //medal select parent
                            var type_reward_parent = h_contentModels.getTypeRewardByID((int)parent);
                            //save parent id  to type_medals
                            medals.type_medals = type_reward_parent.type_reward_id.ToString();
                            //save child id to 
                            medals.medal_class = ((int)medals_view.medals).ToString();
                        }
                        else
                        {
                            //medal select not parent
                            medals.medal_class = null;
                            medals.type_medals = ((int)medals_view.medals).ToString();
                        }
                    }
                }
                else
                {
                    //medal select not parent
                    medals.medal_class = null;
                    medals.type_medals = null;
                }
                medals.reward_number = medals_view.reward_number;
                medals.signature_name = medals_view.signature_name;
                medals.signature_date = medals_view.signature_date;
                medals.descriptions = medals_view.descriptions;
                medals.Years = medals_view.years;
                medals.reward_name_group = null;
            }
            else if (medals.is_collective == 2)
            {
                medals.employee_id = null;
                if (medals_view.departments_id == null)
                {
                    if (string.IsNullOrEmpty(medals_view.reward_name_group))
                    {
                        ViewBag.isAdd = false;
                        ViewBag.result_message = "Xin chọn đơn vị hoặc điền nhóm được tặng thưởng";
                        ViewBag.result = false;
                        return PartialView("../Shared/control_detail_medals", medals_view);
                    }
                    else {
                        medals.reward_name_group = medals_view.reward_name_group;
                        medals.departments_id = null;
                    }
                }
                else {
                    medals.departments_id = medals_view.departments_id;
                    medals.reward_name_group = medals_view.reward_name_group;
                }
                medals.type_reward = 2;
                if (medals_view.medals != null)
                {

                    var type_reward_obj = h_contentModels.getTypeRewardByID((int)medals_view.medals);
                    if (type_reward_obj != null)
                    {
                        var parent = type_reward_obj.parent_id;

                        if (parent != null)
                        {
                            //medal select parent
                            var type_reward_parent = h_contentModels.getTypeRewardByID((int)parent);
                            //save parent id  to type_medals
                            medals.type_medals = type_reward_parent.type_reward_id.ToString();
                            //save child id to 
                            medals.medal_class = ((int)medals_view.medals).ToString();
                        }
                        else
                        {
                            //medal select not parent
                            medals.medal_class = null;
                            medals.type_medals = ((int)medals_view.medals).ToString();
                        }
                    }
                }
                else
                {
                    //medal select not parent
                    medals.medal_class = null;
                    medals.type_medals = null;
                }
                medals.reward_number = medals_view.reward_number;
                medals.signature_name = medals_view.signature_name;
                medals.signature_date = medals_view.signature_date;
                medals.descriptions = medals_view.descriptions;
                medals.Years = medals_view.years;
                
               // medals.is_collective = add_medals_view.is_collective;
            }
           
            else
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Xin vui lòng chọn đối tặng thưởng.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_medals", medals_view);
            }


            h_contentModels.edit_medals(medals);

            ViewBag.result_message = "Cập nhật thành công.";
            ViewBag.result = true;
            if(medals.is_collective==1){
                ViewBag.redirect = "/vi/h_content/list_medals";
            }
            else 
            {
                ViewBag.redirect = "/vi/h_content/list_medals_group";
            }
            return PartialView("../Shared/control_redirect");
        }
        //Xóa huân huy chương
        public ActionResult delete_medals()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_medals(int? id)
        {   var check = h_contentModels.getMedalsByID(id??0);
            
            
            if(check.type_reward==2){
                h_contentModels.deleteMedals(id ?? 0);
                ViewBag.redirect = "/vi/h_content/list_medals";
            }else
            if(check.type_reward==3){
                h_contentModels.deleteMedals(id ?? 0);
                ViewBag.redirect = "/vi/h_content/list_discripline";
            }
            return PartialView("../Shared/control_redirect");
        } 
        
        //Tao loai huan huy chuong
        public ActionResult list_type_reward()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_type_reward(int? id, string text_search, int? parent)
        {
            return control_list_type_reward(id ?? 1, 10, text_search, parent);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_type_reward(int? id, int? pagesize, string text_search, int? parent)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var type_reward_view = new ViewModels.PageListTypeRewardViewModels();
            id = id ?? 1;
            type_reward_view.list_pagesize = sizeDrop;
            type_reward_view.pagesize = pagesize ?? 10;
            type_reward_view.page_list_type_reward = h_contentModels.getTypeRewardBuilder(id ?? 1, pagesize ?? 10, text_search ?? null, parent);
            type_reward_view.list_type_reward_parent = h_contentModels.getListTypeRewardByParent(null);
            return PartialView("../Shared/control_list_type_reward", type_reward_view);
        }

        public ActionResult add_type_reward()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_type_reward(int? id)
        {
            ViewBag.isAdd = true;
            var type_reward_view = new ViewModels.PageListTypeRewardViewModels();
            type_reward_view.list_type_reward_parent = h_contentModels.getListTypeRewardBuilder(null);
            if (id != null)
            {
                type_reward_view.parent_id = id;
            }
            return PartialView("../Shared/control_detail_type_reward", type_reward_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_type_reward(FormCollection collection)
        {
            var type_reward_view = new ViewModels.PageListTypeRewardViewModels();
            TryUpdateModel(type_reward_view);

            web.data.entities.type_reward type_reward = new data.entities.type_reward();
            type_reward.type_reward_name = type_reward_view.type_reward_name;
            type_reward.type_reward_desc = type_reward_view.type_reward_desc;
            type_reward.parent_id = type_reward_view.parent_id;

            int new_id = h_contentModels.createTypeReward(type_reward);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo huân huy chương thành công.";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_type_reward";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tạo không thành công.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_type_reward", type_reward_view);
            }
        }
        public ActionResult edit_type_reward()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_type_reward(int? id)
        {
            ViewBag.isAdd = false;
            var type_reward_view = new ViewModels.PageListTypeRewardViewModels();
            var type_reward = h_contentModels.getTypeRewardByID(id ?? 0);
            type_reward_view.type_reward_id = type_reward.type_reward_id;
            type_reward_view.type_reward_name = type_reward.type_reward_name;
            type_reward_view.type_reward_desc = type_reward.type_reward_desc;
            type_reward_view.list_type_reward_parent  = h_contentModels.getListTypeRewardBuilder(null);
            type_reward_view.parent_id = type_reward.parent_id;

            return PartialView("../Shared/control_detail_type_reward", type_reward_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_type_reward(FormCollection collection)
        {
            var type_reward_view = new ViewModels.PageListTypeRewardViewModels();
            TryUpdateModel(type_reward_view);

            if (string.IsNullOrEmpty(type_reward_view.type_reward_name))
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Hãy nhập tên huân huy chương.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_type_reward", type_reward_view);
            }

            var type_reward = h_contentModels.getTypeRewardByID(type_reward_view.type_reward_id ?? 0);
            type_reward.type_reward_name = type_reward_view.type_reward_name;
            type_reward.type_reward_desc = type_reward_view.type_reward_desc;
            type_reward.parent_id = type_reward_view.parent_id;

            h_contentModels.editTypeReward(type_reward);


            ViewBag.result_message = "cập nhật thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_type_reward";
            return PartialView("../Shared/control_redirect");
        }

        

        //Danh sách phòng ban
        public ActionResult list_departments()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_departments(int? id, string text_search, int? parent)
        {
            return control_list_departments(id ?? 1, 10, text_search, parent);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_departments(int? id, int? pagesize, string text_search, int? parent)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            var departments_view = new ViewModels.PageListdepartmentsViewModels();
            departments_view.list_pagesize = sizeDrop;
            departments_view.pagesize = pagesize ?? 10;
            departments_view.page_list_departments = h_contentModels.getDepartmentsBuilder(id ?? 1, pagesize ?? 10, text_search ?? null, parent);
            departments_view.list_departments_parent = h_contentModels.getListDepartmentsByParent(null);
            return PartialView("../Shared/control_list_departments", departments_view);
        }

        public ActionResult add_departments()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_add_departments(int? id)
        {
            ViewBag.isAdd = true;
            var departments_view = new ViewModels.PageListdepartmentsViewModels();
            
            departments_view.list_departments_parent = h_contentModels.getListDepartmentsBuilder(null);
            if (id != null)
            {
                departments_view.parent_departments = id;
            }
            return PartialView("../Shared/control_detail_department", departments_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_add_departments(FormCollection collection)
        {
            var departments_view = new ViewModels.PageListdepartmentsViewModels();
            TryUpdateModel(departments_view);

            web.data.entities.departments departments = new data.entities.departments();
            departments.departments_name = departments_view.departments_name;
            departments.descriptions = departments_view.descriptions;
            departments.departments_status = departments_view.departments_status;
            departments.parent_departments = departments_view.parent_departments;

            int new_id = h_contentModels.createDepartments(departments);

            if (new_id > 0)
            {
                ViewBag.result_message = "Tạo phòng ban thành công";
                ViewBag.result = true;
                ViewBag.redirect = "/vi/h_content/list_departments";
                return PartialView("../Shared/control_redirect");
            }
            else
            {
                ViewBag.isAdd = true;
                ViewBag.result_message = "Tạo phòng ban lỗi.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_department", departments_view);
            }
        }

        public ActionResult edit_departments()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_edit_departments(int? id)
        {
            ViewBag.isAdd = false;
            var departments_view = new ViewModels.PageListdepartmentsViewModels();
            var departments = h_contentModels.getDepartmentsByID(id ?? 0);
            departments_view.departments_id = departments.departments_id;
            departments_view.departments_name = departments.departments_name;
            departments_view.departments_status = departments.departments_status;
            departments_view.descriptions = departments.descriptions;
            departments_view.parent_departments = departments.parent_departments;
            departments_view.list_departments_parent = h_contentModels.getListDepartmentsBuilder(null);
            return PartialView("../Shared/control_detail_department", departments_view);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_edit_departments(FormCollection collection)
        {
            var deparments_view = new ViewModels.PageListdepartmentsViewModels();
            TryUpdateModel(deparments_view);

            if (string.IsNullOrEmpty(deparments_view.departments_name))
            {
                ViewBag.isAdd = false;
                ViewBag.result_message = "Nhập tên phòng ban.";
                ViewBag.result = false;
                return PartialView("../Shared/control_detail_department", deparments_view);
            }

            var departments = h_contentModels.getDepartmentsByID(deparments_view.departments_id ?? 0);
            departments.departments_id = (int)deparments_view.departments_id;
            departments.departments_name = deparments_view.departments_name;
            departments.descriptions = deparments_view.descriptions;
            departments.departments_status = deparments_view.departments_status;
            departments.parent_departments = deparments_view.parent_departments;

            h_contentModels.editDepartments(departments);

            ViewBag.result_message = "Cập nhật phòng ban thành công.";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/h_content/list_departments";
            return PartialView("../Shared/control_redirect");
        }

    }
}
